Repository: logging-log4j-kotlin
Updated Branches:
  refs/heads/master f39add4d8 -> 1f8ae117b


Rename namedLogger for discoverability

Fixes LOG4J2-2432


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j-kotlin/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/logging-log4j-kotlin/commit/c8fc6e3e
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j-kotlin/tree/c8fc6e3e
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j-kotlin/diff/c8fc6e3e

Branch: refs/heads/master
Commit: c8fc6e3ec550a162851a89b6ea970e73cc171615
Parents: 247c0c1
Author: Raman Gupta <[email protected]>
Authored: Tue Sep 4 17:12:44 2018 -0400
Committer: Raman Gupta <[email protected]>
Committed: Fri Nov 2 02:05:51 2018 -0400

----------------------------------------------------------------------
 .../org/apache/logging/log4j/kotlin/LoggingFactory.kt  | 13 ++++++++++---
 .../org.apache.logging.log4j.kotlin/NamedLoggerTest.kt |  2 +-
 src/site/asciidoc/usage.adoc                           |  6 ++++--
 3 files changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j-kotlin/blob/c8fc6e3e/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/LoggingFactory.kt
----------------------------------------------------------------------
diff --git 
a/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/LoggingFactory.kt
 
b/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/LoggingFactory.kt
index 87ee9a8..d4ee57c 100644
--- 
a/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/LoggingFactory.kt
+++ 
b/log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/LoggingFactory.kt
@@ -23,15 +23,22 @@ import kotlin.reflect.full.companionObject
 /**
  * Logger instantiation by function. Use: `val log = logger()`. The logger 
will be named according to the
  * receiver of the function, which can be a class or object. An alternative 
for explicitly named loggers is
- * the `namedLogger` function.
+ * the [logger(String)] function.
  */
 @Suppress("unused")
 inline fun <reified T : Any> T.logger() = loggerOf(T::class.java)
 
 /**
- * Named logger instantiation by function. Use: `val log = 
namedLogger('MyLoggerName')`. Generally one should
- * prefer the `logger` function to create automatically named loggers.
+ * Named logger instantiation by function. Use: `val log = 
logger('MyLoggerName')`. Generally one should
+ * prefer the `logger` function to create automatically named loggers, but 
this is useful outside of objects,
+ * such as in top-level functions.
  */
+fun logger(name: String): KotlinLogger = 
KotlinLogger(LogManager.getContext(false).getLogger(name))
+
+/**
+ * @see [logger]
+ */
+@Deprecated("Replaced with logger(name)", replaceWith = ReplaceWith("logger"), 
level = DeprecationLevel.WARNING)
 fun namedLogger(name: String): KotlinLogger = 
KotlinLogger(LogManager.getContext(false).getLogger(name))
 
 fun loggerDelegateOf(ofClass: Class<*>): ExtendedLogger {

http://git-wip-us.apache.org/repos/asf/logging-log4j-kotlin/blob/c8fc6e3e/log4j-api-kotlin/src/test/kotlin/org.apache.logging.log4j.kotlin/NamedLoggerTest.kt
----------------------------------------------------------------------
diff --git 
a/log4j-api-kotlin/src/test/kotlin/org.apache.logging.log4j.kotlin/NamedLoggerTest.kt
 
b/log4j-api-kotlin/src/test/kotlin/org.apache.logging.log4j.kotlin/NamedLoggerTest.kt
index 28c0cfb..8171ba7 100644
--- 
a/log4j-api-kotlin/src/test/kotlin/org.apache.logging.log4j.kotlin/NamedLoggerTest.kt
+++ 
b/log4j-api-kotlin/src/test/kotlin/org.apache.logging.log4j.kotlin/NamedLoggerTest.kt
@@ -28,7 +28,7 @@ const val loggerName = "Foo"
 class NamedLoggerTest {
   @Rule @JvmField var init = LoggerContextRule("InfoLogger.xml")
 
-  val log = namedLogger(loggerName)
+  val log = logger(loggerName)
 
   @Test
   fun `Logging from an explicitly named logger logs with the correct name`() {

http://git-wip-us.apache.org/repos/asf/logging-log4j-kotlin/blob/c8fc6e3e/src/site/asciidoc/usage.adoc
----------------------------------------------------------------------
diff --git a/src/site/asciidoc/usage.adoc b/src/site/asciidoc/usage.adoc
index 983936a..71829c8 100644
--- a/src/site/asciidoc/usage.adoc
+++ b/src/site/asciidoc/usage.adoc
@@ -106,15 +106,17 @@ class MyClass: BaseClass {
 
 ==== Explicitly Named Loggers
 
-An explicitly-named logger may be obtained via the `namedLogger` function:
+An explicitly-named logger may be obtained via the `logger` function that 
takes a `name` parameter:
 
 [source,kotlin]
 ----
 import org.apache.logging.log4j.kotlin
 
 class MyClass: BaseClass {
-  val logger = namedLogger("MyCustomLoggerName")
+  val logger = logger("MyCustomLoggerName")
 
   ...
 }
 ----
+
+This is also needed in scopes that do not have a `this` Object, such as 
top-level functions.

Reply via email to