Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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.

...

Image Added

Create the log4j.properties file

...

Create a new text file in /opt/lucee/tomcat/lib/ called log4j.properties.

Code Block
languagebash
$ cd /opt/lucee/tomcat/lib/

...


$ sudo vim log4j.properties



Then add the following text to it:

Code Block
languagebash
# 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

...

Image Added

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:

...

Copy the log4j-1.2.17.jar file to /opt/lucee/tomcat/libdirectory, and you're done with this step.


Code Block
languagebash
$ cd /opt/lucee/tomcat/lib/

...


$ sudo wget http://archive.apache.org/dist/logging/log4j/1.2.17/log4j-1.2.17.jar

...

Image Added

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":

https://tomcat.apache.org/download-80.cgi


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


juli log4j download

Set the Context Log Attribute

...

In that file, we need to update this line:


Code Block
<Context useHttpOnly="true">

to this:

Code Block
<Context useHttpOnly="true" swallowOutput="true">

context swallow outputImage RemovedImage Added

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
languageapplescript
$ cd /opt/lucee/tomcat/conf

...


$ sudo mv logging.properties logging.properties.bak

...

Image Added

 

I would also recommend that you clean out the previous logs from the /opt/lucee/tomcat/logs/directory. To do this, just stop the Lucee service, delete the logs, then start it again. This will make verifying your config much easier, as you can see at a glance if your new logging config has taken effect.

Code Block
languagebash
$ sudo /etc/init.d /lucee_ctl stop

...


$ sudo rm - rf /opt/lucee/tomcat/logs/*

...


$ sudo /etc/init.d/lucee_ctl start

...

Image Added

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.

...

Image Added

Note that all useful log data is being directed to the catalina.out file.

...