|
| 1 | +# Debugging |
| 2 | + |
| 3 | +## Logging |
| 4 | + |
| 5 | +### JVM |
| 6 | + |
| 7 | +For JVM targets, the Kotlin SDK uses the `slf4j` logger. The build configuration can be updated to enable log output. |
| 8 | + |
| 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: |
| 11 | + |
| 12 | +``` |
| 13 | +implementation("org.slf4j:slf4j-simple:1.7.30") |
| 14 | +``` |
| 15 | + |
| 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: |
| 17 | + |
| 18 | +``` |
| 19 | +-Dorg.slf4j.simpleLogger.defaultLogLevel=TRACE -Dorg.slf4j.simpleLogger.showDateTime=true |
| 20 | +``` |
| 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. |
| 23 | + |
| 24 | + |
| 25 | +#### CRT Logs |
| 26 | + |
| 27 | +JVM system properties for CRT related logs |
| 28 | + |
| 29 | + |
| 30 | +| Property | Description | |
| 31 | +| ----------------------------| -----------------------------------------------------------------------------------------------------------------| |
| 32 | +| `aws.crt.log.level` | Specify log level `None`, `Fatal`, `Error`, `Warn`, `Info`, `Debug`, `Trace` | |
| 33 | +| `aws.crt.log.destination` | The destination to log to `None`, `Stdout`, `Stderr`, `File`. By default when level is not `None` stderr is used | |
| 34 | +| `aws.crt.log.filename` | Redirect logs to a file | |
| 35 | + |
| 36 | + |
| 37 | +## Error Metadata |
| 38 | + |
| 39 | +The raw protocol response is usually available on exceptions if you need access to additional response details (headers, status code, etc). |
| 40 | + |
| 41 | + |
| 42 | +```kotlin |
| 43 | +try { |
| 44 | + ... |
| 45 | +} catch(ex: AwsServiceException) { |
| 46 | + val httpResp = ex.sdkErrorMetadata.protocolResponse as? HttpResponse |
| 47 | + if (httpResp != null) { |
| 48 | + println(httpResp.headers) |
| 49 | + println(httpResp.body.readAll()?.decodeToString()) |
| 50 | + } |
| 51 | +} |
| 52 | +``` |
0 commit comments