...
The following is intended to be a guide on how to go about downloading and installing log4J on a system that was built using the Lucee Installers.
Review the Tomcat Guide (optional)
Much of the following is just a customized from of the Tomcat documentation, which, if you want to review the original, can be found here.
Installing Log4J Walkthough
The following guide will assume you've installed Lucee to the default location of /opt/lucee, and the directories stated here will be written accordingly. If you installed Lucee to a different location, you will need to update the example directories to match where you installed Lucee.
In the following example, I will be upgrading a Lucee 5 installation on Ubuntu 16.4 LTS. If you're not running this setup, you may need to interpolate these commands a bit, but the general principals will be the same.
Create the log4j.properties file
Start out by creating a standard config file. This config file will force the majority of relevant logging info to be logged in the catalina.out file. When we're done, other log files will be created, but they should not contain any actual information with the exception of a single line on occasion.
...
Code Block | ||
---|---|---|
| ||
# set the log level and name the root logger # Available Levels: DEBUG, INFO, WARN, ERROR, FATAL log4j.rootLogger=INFO, ROOT # set the root logger class log4j.appender.ROOT=org.apache.log4j.RollingFileAppender # set the name/location of the log file to rotate log4j.appender.ROOT.File=${catalina.base}/logs/catalina.out # set the max file size before a new file (and backups) are made log4j.appender.ROOT.MaxFileSize=150MB # set how many iterations of the log file to keep before deleting old logs log4j.appender.ROOT.MaxBackupIndex=10 # set log text formatting log4j.appender.ROOT.layout=org.apache.log4j.PatternLayout log4j.appender.ROOT.layout.ConversionPattern=%p %t %c - %m%n # create a logger for catalina log4j.logger.org.apache.catalina=INFO, ROOT |
Download Log4j
At the time of this writing, log4j 2.0 beta is available, but the Tomcat documentation for log4j (link above) says that Tomcat requires the 1.2.x version, which can be found in the archived versions here:
...
Code Block | ||
---|---|---|
| ||
$ cd /opt/lucee/tomcat/lib/ $ sudo wget http://archive.apache.org/dist/logging/log4j/1.2.17/log4j-1.2.17.jar |
Download Tomcat Extras
There are two additional JAR's Tomcat will need in order to use Log4j, these are tomcat-juli.jar
and tomcat-juli-adapters.jar
These are "extras" that the Tomcat project keeps up to date and provides downloads for. You can download these two files from the Tomcat download page, under "Extras":
...
Code Block |
---|
$ cd /opt/lucee/tomcat/lib/ $ sudo wget http://apache.osuosl.org/tomcat/tomcat-8/v8.0.36/bin/extras/tomcat-juli-adapters.jar $ sudo wget http://apache.osuosl.org/tomcat/tomcat-8/v8.0.36/bin/extras/tomcat-juli.jar |
Set the Context Log Attribute
We will need to update the default context config so that logging data is "trapped" and placed in the default root logger. In order to do this, we need to edit the default context file in/opt/lucee/tomcat/conf/context.xml
.
...
Code Block |
---|
<Context useHttpOnly="true" swallowOutput="true"> |
Cleanup and Restart
Last, we need to remove the previous logging.properties file as Tomcat will still read that and create empty log files if we do not remove it. Just delete it or rename it if you want to keep it around for some reason.
...
Code Block | ||
---|---|---|
| ||
$ sudo /etc/init.d /lucee_ctl stop $ sudo rm - rf /opt/lucee/tomcat/logs/* $ sudo /etc/init.d/lucee_ctl start |
Verify Your Config
Once you've restarted Tomcat. Check your log directory and ensure that the bulk of the log data is now being stored in your catalina.out file. An example resulting log directory can be seen in the image below.
...