How to create customized log appender in fabric mode ?
Environment
- Red Hat JBoss Fuse
- 6.1.0
Issue
- There are some components (deployed in fabric) that need to log in separate file (apart from
karaf.log
). - Hence configured a custom appender on file
org.ops4j.pax.logging.cfg
but after a while (about half a hour) the component stops logging. - Here's the piece of log configuration that is added to org.ops4j.pax.logging.cfg;
log4j.category.com.mycompany.sample.examples=TRACE, example
log4j.appender.example=org.apache.log4j.RollingFileAppender
log4j.appender.example.layout=org.apache.log4j.PatternLayout
log4j.appender.example.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} | %-5.5p | %c{1} | %M | %m%n
log4j.appender.example.file=${karaf.data}/log/examples.log
log4j.appender.example.append=true
log4j.appender.example.maxFileSize=10MB
log4j.appender.example.maxBackupIndex=10
Resolution
Let say there is already a profile 'quickstart-logs' . This profile refer to an endpoint(webservice/amq
) which prints logs when invoked.
Steps to follow:
-
Now go to
Hawtio
web-console and as per attached doc(screenshots.doc) follow steps. -
fabric:profile-refresh
quickstart-logs. -
container-create-child
root TestB -
container-create-child
root TestA -
container-add-profile
TestB quickstart-logs
To check logs go to location:
${karaf.home}/instances/TestB/data/log/
${karaf.home}/instances/TestA/data/log/
Root Cause
Properties should be profile based and profiles are than applied to container. Hence we can have a custom profile with org.ops4j.pax.logging.properties
and to which ever container we will apply this profile, that container will generate logs as per org.ops4j.pax.logging.properties
configuration.
Attachments
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments