<dependency> <groupId>org.apache.skywalking</groupId> <artifactId>apm-toolkit-log4j-1.x</artifactId> <version>{project.release.version}</version> </dependency>
log4j.appender.CONSOLE.layout=org.apache.skywalking.apm.toolkit.log.log4j.v1.x.TraceIdPatternLayout
%T
in layout.ConversionPattern
( In 2.0-2016, you should use %x, Why change? )log4j.appender.CONSOLE.layout.ConversionPattern=%d [%T] %-5p %c{1}:%L - %m%n
-javaagent
to active the SkyWalking tracer, log4j will output traceId, if it existed. If the tracer is inactive, the output will be TID: N/A
.Your only need to replace pattern %T
with %T{SW_CTX}
.
When you use -javaagent
to active the SkyWalking tracer, log4j will output SW_CTX: [$serviceName,$instanceName,$traceId,$traceSegmentId,$spanId]
, if it existed. If the tracer is inactive, the output will be SW_CTX: N/A
.
The gRPC report could forward the collected logs to SkyWalking OAP server, or SkyWalking Satellite sidecar. Trace id, segment id, and span id will attach to logs automatically. You don't need to change the layout.
GRPCLogClientAppender
in log4j.propertieslog4j.rootLogger=INFO,CustomAppender log4j.appender.CustomAppender=org.apache.skywalking.apm.toolkit.log.log4j.v1.x.log.GRPCLogClientAppender log4j.appender.CustomAppender.layout=org.apache.log4j.PatternLayout log4j.appender.CustomAppender.layout.ConversionPattern=[%t] %-5p %c %x - %m%n
log.max_message_size=${SW_GRPC_LOG_MAX_MESSAGE_SIZE:10485760}