|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package aws.smithy.kotlin.runtime.telemetry.logging.crt |
| 7 | + |
| 8 | +import aws.sdk.kotlin.crt.WithCrt |
| 9 | +import aws.sdk.kotlin.crt.log |
| 10 | +import aws.smithy.kotlin.runtime.telemetry.logging.LogLevel |
| 11 | +import aws.smithy.kotlin.runtime.telemetry.logging.LogRecordBuilder |
| 12 | +import aws.smithy.kotlin.runtime.telemetry.logging.Logger |
| 13 | +import aws.smithy.kotlin.runtime.telemetry.logging.MessageSupplier |
| 14 | +import aws.sdk.kotlin.crt.Config as CrtConfig |
| 15 | +import aws.sdk.kotlin.crt.LogLevel as CrtLogLevel |
| 16 | + |
| 17 | +public class CrtLogger(public val name: String, public val config: CrtConfig) : Logger, WithCrt() { |
| 18 | + override fun trace(t: Throwable?, msg: MessageSupplier) { |
| 19 | + log(CrtLogLevel.Trace, msg()) |
| 20 | + } |
| 21 | + |
| 22 | + override fun debug(t: Throwable?, msg: MessageSupplier) { |
| 23 | + log(CrtLogLevel.Debug, msg()) |
| 24 | + } |
| 25 | + |
| 26 | + override fun info(t: Throwable?, msg: MessageSupplier) { |
| 27 | + log(CrtLogLevel.Info, msg()) |
| 28 | + } |
| 29 | + |
| 30 | + override fun warn(t: Throwable?, msg: MessageSupplier) { |
| 31 | + log(CrtLogLevel.Warn, msg()) |
| 32 | + } |
| 33 | + |
| 34 | + override fun error(t: Throwable?, msg: MessageSupplier) { |
| 35 | + log(CrtLogLevel.Error, msg()) |
| 36 | + } |
| 37 | + |
| 38 | + override fun isEnabledFor(level: LogLevel): Boolean = config.logLevel.ordinal >= level.ordinal |
| 39 | + |
| 40 | + override fun atLevel(level: LogLevel): LogRecordBuilder = CrtLogRecordBuilder(this, level) |
| 41 | +} |
0 commit comments