|
7 | 7 | For JVM targets, the Kotlin SDK uses the `slf4j` logger. The build configuration can be updated to enable log output. |
8 | 8 |
|
9 | 9 | 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: |
11 | 11 |
|
12 | | -``` |
13 | | -implementation("org.slf4j:slf4j-simple:1.7.30") |
14 | | -``` |
| 12 | +#### Gradle dependencies |
15 | 13 |
|
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: |
17 | 15 |
|
18 | 16 | ``` |
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") |
20 | 20 | ``` |
21 | 21 |
|
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 | +``` |
23 | 41 |
|
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#). |
25 | 44 |
|
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`: |
27 | 46 |
|
| 47 | +```xml |
| 48 | +<Root level="trace"> |
28 | 49 | ``` |
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. |
35 | 54 |
|
36 | 55 | #### CRT Logs |
37 | 56 |
|
|
0 commit comments