Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.16.3. Logging per Application
Overview Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Using Mapped Diagnostic Context (MDC) logging, you create a separate log file for each of your applications. The basic idea of MDC logging is that you associate each logging message with a particular context (for example, by associating it with a set of key-value pairs). Later on, when it comes to writing the log stream, you can use the context data to sort or filter the logging messages in various ways.
Note
MDC logging is supported only by log4j and slf4j.
Application key Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To use MDC logging, you must define a unique MDC key for each of your applications. The MDC key is a string that is associated with one application or logging context. At runtime, you can then use the application key to sort logging messages and write them into separate files for each application key.
Enabling per application logging Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To enable per application logging:
- In each of your applications, edit the Java source code to define a unique application key.If you are using slf4j, add the following static method call to your application:
org.slf4j.MDC.put("app.name","MyFooApp");
org.slf4j.MDC.put("app.name","MyFooApp");
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you are using log4j, add the following static method call to your application:org.apache.log4j.MDC.put("app.name","MyFooApp");
org.apache.log4j.MDC.put("app.name","MyFooApp");
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Edit the
etc/org.ops4j.pax.logging
PID to customize the sift appender.- Set
log4j.appender.sift.key
toapp.name
. - Set
log4j.appender.sift.appender.file
to=${karaf.data}/log/$\\{app.name\\}.log
.
- Edit the
etc/org.ops4j.pax.logging
PID to add the sift appender to the root logger.JBossFuse:karaf@root> config:edit org.ops4j.pax.logging JBossFuse:karaf@root> config:propset log4j.rootLogger "INFO, out, sift, osgi:VmLogAppender" JBossFuse:karaf@root> config:update
JBossFuse:karaf@root> config:edit org.ops4j.pax.logging JBossFuse:karaf@root> config:propset log4j.rootLogger "INFO, out, sift, osgi:VmLogAppender" JBossFuse:karaf@root> config:update
Copy to Clipboard Copied! Toggle word wrap Toggle overflow