You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2023/01/30 01:14:01 UTC

[logging-log4j-kotlin] 01/11: Synchronize changes in usage.adoc versus README.md

This is an automated email from the ASF dual-hosted git repository.

mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j-kotlin.git

commit 1f673416c0826d453f6796b8d528e966d5a29985
Author: Matt Sicker <ma...@apache.org>
AuthorDate: Sun Jan 29 18:26:08 2023 -0600

    Synchronize changes in usage.adoc versus README.md
---
 README.md                    |  2 +-
 src/site/asciidoc/usage.adoc | 44 ++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 1e88946..a2f72a8 100644
--- a/README.md
+++ b/README.md
@@ -70,7 +70,7 @@ Beginning in version 1.3.0, an extension property is also available on classes:
 import org.apache.logging.log4j.kotlin.logger
 
 class MyClass: BaseClass {
-  init {
+  fun doStuff() {
     logger.info("Hello, world!")
   }
 }
diff --git a/src/site/asciidoc/usage.adoc b/src/site/asciidoc/usage.adoc
index 71829c8..b017926 100644
--- a/src/site/asciidoc/usage.adoc
+++ b/src/site/asciidoc/usage.adoc
@@ -41,7 +41,7 @@ import org.apache.logging.log4j.kotlin.Logging
 class MyClass: BaseClass {
   companion object : Logging
 
-  ...
+  // ...
 }
 ----
 
@@ -54,12 +54,48 @@ import org.apache.logging.log4j.kotlin
 class MyClass: BaseClass {
   val logger = logger()
 
-  ...
+  // ...
 }
 ----
 
 The function `logger()` is an extension function on the `Any` type (or more specifically, any type `T` that extends `Any`).
 
+Beginning in version 1.3.0, an extension property is also available on classes:
+
+[source,kotlin]
+----
+import org.apache.logging.log4j.kotlin.logger
+
+class MyClass: BaseClass {
+  fun doStuff() {
+    logger.info("Hello, world!")
+  }
+}
+----
+
+Also added in version 1.3.0, the `ThreadContext` API has two facade objects provided: `ContextMap` and `ContextStack`.
+
+[source,kotlin]
+----
+import org.apache.logging.log4j.kotlin.ContextMap
+import org.apache.logging.log4j.kotlin.ContextStack
+
+ContextMap["key"] = "value"
+assert(ContextMap["key"] == "value")
+assert("key" in ContextMap)
+
+ContextMap += "anotherKey" to "anotherValue"
+ContextMap -= "key"
+
+ContextStack.push("message")
+assert(!ContextStack.empty)
+assert(ContextStack.depth == 1)
+val message = ContextStack.peek()
+assert(message == ContextStack.pop())
+assert(ContextStack.empty)
+----
+
+
 === API Documentation
 
 See https://logging.apache.org/TODO[KDocs].
@@ -100,7 +136,7 @@ import org.apache.logging.log4j.kotlin
 class MyClass: BaseClass {
   val logger = SomeOtherClass.logger()
 
-  ...
+  // ...
 }
 ----
 
@@ -115,7 +151,7 @@ import org.apache.logging.log4j.kotlin
 class MyClass: BaseClass {
   val logger = logger("MyCustomLoggerName")
 
-  ...
+  // ...
 }
 ----