kamon-logback

Github星跟蹤圖

kamon-logback

Build Status
Gitter
Maven Central

The kamon-logback module requires you to start your application using the AspectJ Weaver Agent.

Getting Started

Kamon Logback is currently available for Scala 2.10, 2.11, 2.12 and 2.13.

Supported releases and dependencies are shown below., kamon, status, jdk, scala, :------:, :------:, :----:, ------------------, 1.0.6, stable, 1.8+, 2.10, 2.11, 2.12, 2.0.0, stable, 1.8+, 2.11, 2.12, 2.13

To get started with SBT, simply add the following to your build.sbt or pom.xml
file:

libraryDependencies += "io.kamon" %% "kamon-logback" % "2.0.0"
<dependency>
    <groupId>io.kamon</groupId>
    <artifactId>kamon-logback_2.12</artifactId>
    <version>2.0.0</version>
</dependency>

Logging TraceID

Inserting a conversionRule allows you to incorporate the trace ID for a request into your Logback layout. Here is a simple example logback.xml configuration that does this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="false" debug="false">
  <conversionRule conversionWord="traceID" converterClass="kamon.instrumentation.logback.tools.TraceIDConverter" />

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{yyyy-MM-dd HH:mm:ss}, %-5level, %traceID, %c{0} -> %m%n</pattern>
    </encoder>
  </appender>

  <root level="DEBUG">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

Propagating TraceID to AsyncAppender

If you choose to use AsyncAppender, your trace ID will automatically be propagated to the thread where the log is actually published. No configuration needed. The same applies for the span ID. You can use them in the logback pattern like this:

 <pattern>%d{yyyy-MM-dd HH:mm:ss}, %-5level, %X{kamonTraceID}, %X{kamonSpanID}, %c{0} -> %m%n</pattern>

You can also add custom values to MDC. To do this, simply add the key value in the library configuration:

kamon.logback.mdc-traced-local-keys = [ userID ].
kamon.logback.mdc-traced-broadcast-keys = [ requestID ]

Then, add the value to the kamon context:

Context
  .create(Span.Key, span)
  .withKey(Key.broadcastString("userID"), Some("user-1"))
  .withKey(Key.local[Option[String]("requestID", None), Some("request-id") {
  // loggers called in this context will have access to the userID, requestID
}

Note: While in Kamon you can have one local key and one broadcast key with the same name, in MDC this is not possible. In this case only the broadcast key will be stored in MDC (will be present in the logs)

Counting Log Entries

Sometimes you need to know how many log entries your application produce as a Kamon counter, in order to easily visualize that information, and more important, be able to alert on those metrics.

This library allows you to do that by just changing the logback.xml file and adding a simple appender, please notice the appender called COUNTER:

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="false" debug="false">
  <conversionRule conversionWord="traceID" converterClass="kamon.instrumentation.logback.tools.TraceIDConverter" />

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{yyyy-MM-dd HH:mm:ss}, %-5level, %traceID, %c{0} -> %m%n</pattern>
    </encoder>
  </appender>
  <appender name="COUNTER" class="kamon.instrumentation.logback.tools.EntriesCounterAppender"/>

  <root level="DEBUG">
    <appender-ref ref="STDOUT" />
    <appender-ref ref="COUNTER" />
  </root>
</configuration>

The Kamon counter is named "log.events", and is refined with the tags:

"level" → "ERROR", "WARN", "INFO", "DEBUG", "TRACE" (One of those values, is the level of the event.)

"component" → "logback" (Always this value)

概覽

名稱與所有者kamon-io/kamon-logback
主編程語言Scala
編程語言Scala (語言數: 2)
平台
許可證
發布數13
最新版本名稱v2.0.2 (發布於 2019-10-29 15:36:59)
第一版名稱v1.0.0-RC7 (發布於 )
創建於2017-06-28 14:06:31
推送於2020-03-18 16:02:39
最后一次提交2020-03-18 17:02:32
星數12
關注者數8
派生數17
提交數95
已啟用問題?
問題數6
打開的問題數0
拉請求數19
打開的拉請求數0
關閉的拉請求數2
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?
去到頂部