Skip to content

Commit 1060c28

Browse files
authored
docs: update the debugging guide to demonstrate how to use Log4j2 for logging (#634)
1 parent c66f1a1 commit 1060c28

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"id": "eff54b49-15bb-424d-a91e-04b32bfc6fc9",
3+
"type": "documentation",
4+
"description": "Update the debugging guide to demonstrate how to use Log4j2 for logging"
5+
}

docs/debugging.md

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,50 @@
77
For JVM targets, the Kotlin SDK uses the `slf4j` logger. The build configuration can be updated to enable log output.
88

99
While any `slf4j`-compatible log library may be used, here is an example to enable log output from the SDK in JVM
10-
programs:
10+
programs via Log4j2:
1111

12-
```
13-
implementation("org.slf4j:slf4j-simple:1.7.30")
14-
```
12+
#### Gradle dependencies
1513

16-
To view low-level request and response log output and the time of the log entry, specify this as JVM parameters to the executing program:
14+
Add the following dependencies via Gradle:
1715

1816
```
19-
-Dorg.slf4j.simpleLogger.defaultLogLevel=TRACE -Dorg.slf4j.simpleLogger.showDateTime=true
17+
implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.17.2")
18+
implementation("org.apache.logging.log4j:log4j-core:2.17.2")
19+
implementation("org.apache.logging.log4j:log4j-api:2.17.2")
2020
```
2121

22-
The log level can be adjusted up as needed to DEBUG, INFO, WARN, or ERROR. [See here](http://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html) for all properties for the simple logger.
22+
#### Log4j2 configuration file
23+
24+
Create a file named **log4j2.xml** in your **resources** directory (e.g., **\<project-dir>/src/main/resources**). Add
25+
the following XML configuration to the file:
26+
27+
```xml
28+
<Configuration status="ERROR">
29+
<Appenders>
30+
<Console name="Out">
31+
<PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} %-5p %c:%L - %encode{%m}{CRLF}%n"/>
32+
</Console>
33+
</Appenders>
34+
<Loggers>
35+
<Root level="info">
36+
<AppenderRef ref="Out"/>
37+
</Root>
38+
</Loggers>
39+
</Configuration>
40+
```
2341

24-
#### Unit Tests
42+
For more information on how to customize logging, see
43+
[Log4j2's Configuration guide](https://logging.apache.org/log4j/2.x/manual/configuration.html#).
2544

26-
To enable logging in JVM unit tests, the JVM properties can be passed via the Gradle `test` task. Here is an example snippet from a `build.gradle.kts` file:
45+
To view low-level request and response log output and the time of the log entry, change the appender level to `trace`:
2746

47+
```xml
48+
<Root level="trace">
2849
```
29-
tasks.test {
30-
options {
31-
jvmArgs = listOf("-Dorg.slf4j.simpleLogger.defaultLogLevel=TRACE", "-Dorg.slf4j.simpleLogger.showDateTime=true")
32-
}
33-
}
34-
```
50+
51+
#### Unit Tests
52+
53+
To enable or customize logging in JVM unit tests, add a **log4j2-test.xml** file to the **resources** directory.
3554

3655
#### CRT Logs
3756

0 commit comments

Comments
 (0)