* Dependency the toolkit, such as using maven or gradle ```xml org.apache.skywalking apm-toolkit-log4j-2.x {project.release.version} ``` # Print trace ID in your logs * Config the `[%traceId]` pattern in your log4j2.xml ```xml ``` * Support log4j2 AsyncRoot , No additional configuration is required. Refer to the demo of log4j2.xml below. For details: [Log4j2 Async Loggers](https://logging.apache.org/log4j/2.x/manual/async.html) ```xml ``` * Support log4j2 AsyncAppender , No additional configuration is required. Refer to the demo of log4j2.xml below. For details: [All Loggers Async](https://logging.apache.org/log4j/2.x/manual/async.html#AllAsync) Log4j-2.9 and higher require disruptor-3.3.4.jar or higher on the classpath. Prior to Log4j-2.9, disruptor-3.0.0.jar or higher was required. This is simplest to configure and gives the best performance. To make all loggers asynchronous, add the disruptor jar to the classpath and set the system property `log4j2.contextSelector` to `org.apache.logging.log4j.core.async.AsyncLoggerContextSelector`. ```xml %d %p %c{1.} [%t] [%traceId] %m %ex%n ``` For details: [Mixed Sync & Async](https://logging.apache.org/log4j/2.x/manual/async.html#MixedSync-Async) Log4j-2.9 and higher require disruptor-3.3.4.jar or higher on the classpath. Prior to Log4j-2.9, disruptor-3.0.0.jar or higher was required. There is no need to set system property `Log4jContextSelector` to any value. ```xml %d %p %class{1.} [%t] [%traceId] %location %m %ex%n ``` * Support log4j2 AsyncAppender, For details: [Log4j2 AsyncAppender](https://logging.apache.org/log4j/2.x/manual/appenders.html) ```xml ``` * When you use `-javaagent` to active the sky-walking tracer, log4j2 will output **traceId**, if it existed. If the tracer is inactive, the output will be `TID: N/A`. # gRPC reporter The gRPC report could forward the collected logs to SkyWalking OAP server, or [SkyWalking Satellite sidecar](https://github.com/apache/skywalking-satellite). Trace id, segment id, and span id will attach to logs automatically. You don't need to change the layout. * Add `GRPCLogClientAppender` in log4j2.xml ```xml ``` * Add config of the plugin or use default ```properties plugin.toolkit.log.grpc.reporter.server_host=${SW_GRPC_LOG_SERVER_HOST:127.0.0.1} plugin.toolkit.log.grpc.reporter.server_port=${SW_GRPC_LOG_SERVER_PORT:11800} plugin.toolkit.log.grpc.reporter.max_message_size=${SW_GRPC_LOG_MAX_MESSAGE_SIZE:10485760} plugin.toolkit.log.grpc.reporter.upstream_timeout=${SW_GRPC_LOG_GRPC_UPSTREAM_TIMEOUT:30} ```