- Change the location of the Karaf log file
- Change the Karaf log file name, size, and retention rate
- Write Karaf system output to a log file
What you will learn:
- Overwrite default Karaf configuration files
- Create new directories in custom Karaf server
- Set Karaf environment variables
Please see the post "Create a custom Apache Karaf server" for the initial setup.
Apache Karaf has poor initial logging configurations for production. Below are instructions on how to change it.
Step 1: Overwrite default Karaf logging configuration file
The default Karaf logging configuration file is etc/org.ops4j.pax.logging.cfg . The default Karaf log settings is to write to data/log/karaf.log , with a 1MB file size limit and a 10 file retention. To overwrite, create the file src/main/resources/etc/org.ops4j.pax.logging.cfg . We are changing the log file to logs/dekantar.log, with a daily rotating log.
The contents of etc/org.ops4j.pax.logging.cfg should look like
# Root logger log4j.rootLogger=INFO, daily, osgi:* log4j.throwableRenderer=org.apache.log4j.OsgiThrowableRenderer # Daily File appender log4j.appender.daily=org.apache.log4j.DailyRollingFileAppender log4j.appender.daily.layout=org.apache.log4j.PatternLayout log4j.appender.daily.layout.ConversionPattern=%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n log4j.appender.daily.file=${karaf.home}/logs/dekantar.log log4j.appender.daily.datePattern='.'yyyy-MM-dd
See https://github.com/juttayaya/karaf/blob/master/karaf3/custom-karaf/custom-karaf-server/src/main/resources/etc/org.ops4j.pax.logging.cfg for a full example.
Step 2: Create the logs directory
Create the logs directory in /src/main/resources/logs.
See https://github.com/juttayaya/karaf/tree/master/karaf3/custom-karaf/custom-karaf-server/src/main/resources/logs for a full example
Step 3: Create the Karaf system output logfile
In Karaf 3.0.4, the Karaf system output log file is defined in the file bin/setenv as the variable KARAF_REDIRECT . If the variable is not defined, then the system output goes to /dev/null . In previous versions of Karaf 3, the system output logfile was hardcoded as data/log/karaf.out .
To change the system output logfile to logs/dekantar.out , create the file src/main/resources/bin/setenv
The content of bin/setenv should look like
#!/bin/sh ENVHOME=`dirname $0` LOG_HOME=`cd $ENVHOME/..;pwd` export KARAF_REDIRECT=${LOG_HOME}/logs/dekantar.out
No comments:
Post a Comment