Closed duan2ping closed 1 year ago
@duan2ping hmm what do you mean? pax-logging gives you all popular Logging facades access to single "backend".
I know nothing about Apache Skywalking but if you mean passing log events from pax logging to Skywalking, I think you need custom appender and Pax Logging contains some examples about how to do it.
@grgrzybek Thanks for your answer. I need to modify the layout of Pax Logging to the layout of Skywalking extension. If the Skywalking layout is converted to Pax Logging layout by customizing the layout, it may be a bit troublesome. Is there any way to use Skywalking layout directly?
Hmm, I'd need more information - first - is Skywalking OSGi-aware at all? By layout you mean the format of messages of the logging events? Or simply the format of the lines written to stdout/file?
Pax Logging doesn't assume any layout (though there are default layouts of Logback/Log4j1/Log4j2)... What is the Skywalking layout?
Hi! I am afraid that Skywalking does not support OSGi. (https://github.com/apache/skywalking/discussions/7959)
Yes, it is the message format. As shown below, I need to change "log4j2.appender.console.layout.type" to TraceIdPatternLayout of Skywalking extension.
Configuration file of Karaf: org.ops4j.pax.logging.cfg Configuration content:
log4j2.appender.console.type = Console
log4j2.appender.console.name = Console
log4j2.appender.console.layout.type = PatternLayout
log4j2.appender.console.layout.pattern = ${log4j2.out.pattern}
I tried googling TraceIdPatternLayout
and I found https://github.com/apache/skywalking/blob/c467e4df06cefd5914082ed8cc093d538dc42e2c/test/e2e-v2/java-test-service/e2e-service-provider/src/main/resources/log4j.properties
However it's for Log4j1...
pax.logging (both for log4j1 and log4j2) has fragment samples where you (in theory) could implement any kind of extension. For example, this is a sample List
appender which can be configured like this:
builtin.list.log4j2.appender.l.type = List
builtin.list.log4j2.appender.l.name = l
I believe you can create your own layout as well...
Remember that layout is only an event → message converted and I think Skywalking needs some kind of appender to tunnel events from the logging framework to Skywalking itself...
Okay, thank you very much! let me give it a try.
I'm sorry, TraceIdPatternLayout is the layout of Skywalking extension log4j1, but my example is log4j2. Skywalking-Log4j2 This is how Skywalking is configured in log4j2.
At first glance, after checking https://github.com/apache/skywalking-java/blob/e6447d517558031f49cc4450467e41b644320071/apm-application-toolkit/apm-toolkit-log4j-2.x/src/main/java/org/apache/skywalking/apm/toolkit/log/log4j/v2/x/TraceIdConverter.java I see this JAR is a log4j2 plugin (see its META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat
).
So you'd have to turn this plugin into a fragment bundle for pax-logging-log4j2 the same way as https://github.com/ops4j/org.ops4j.pax.logging/blob/main/pax-logging-samples/fragment-log4j2/pom.xml is a Log4j2 plugin and OSGi fragment, while the POM uses:
<annotationProcessor>org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor</annotationProcessor>
Thank you very much! let me give it a try.
any news @duan2ping ?
any news about this issue @duan2ping ?
I'm very sorry, due to some work changes, I haven't tried again. Thank you very much for your help.
How to configure pax-logging to use Apache skywalking in karaf?