Dashboard > CruiseControl > Log4jAndCruiseControl
Log4jAndCruiseControl Log In View a printable version of the current page.

Added by Eric Pugh , last edited by Daniel Patterson on Jan 31, 2006  (view change)
Labels: 
(None)

Monitoring CruiseControl itself

As much as we like CruiseControl, to some developers it feels like it is a bit of blackbox. People want feedback that their build is in the queue.. Or, if you have a really long running build, what step the build has reached. However, how do you expose this information? There are a couple approches:

Use tail -f cruisecontrol.log and just see what is happening. This is simple and easy, but requires logging onto the box that is running cruisecontrol.

Expose the log files via HTTP and allow people to download. This works while logs are small, but is not a viable long term solution.

Or, best of all, use the existing infrastructure provided with Log4J and Chainsaw!.

Steps to Follow:
1) Add a custom log4j.properties that overrides the one in cruisecontrol.jar by putting this file in /main/dist/log4j.properties:

 
log4j.rootCategory=INFO,A1,FILE, HUB

# A1 is to console
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=[cc]%d{MMM-dd HH:mm:ss} %-14.14c{1}- %m%n

# FILE is file logger with rotation
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d [%-9t] %-5p %-16c{1} %x- %m%n
log4j.appender.FILE.File=cruisecontrol3.log
log4j.appender.FILE.MaxFileSize=5000KB
log4j.appender.FILE.MaxBackupIndex=4

# HUB is a socket hub appender
log4j.appender.HUB=org.apache.log4j.net.SocketHubAppender
log4j.appender.HUB.layout=org.apache.log4j.PatternLayout
log4j.appender.HUB.layout.ConversionPattern=[cc]%d{MMM-dd HH:mm:ss} %-14.14c{1}- %m%n
log4j.appender.HUB.port=9004
 

Make sure the port you picked isn't in use for something else! Also, I have had to put log4j.properties in the cruisecontrol.jar, although this shouldn't be needed.

2) Then, fire up Chainsaw, a GUI for Log4j. It is available via Java WebStart http://logging.apache.org/log4j/docs/chainsaw.html

3) You then want to create a new SocketHubReciever, and provide the port and ip address of the CruiseControl machine. Also give the receiver a name as well like "CruiseControl Events" and pick the threshold, like INFO or DEBUG of events you want.

Monitoring your builds

Now it's nice to monitor CruiseControl with Chainsaw, but what about your builds? In our setup, the default logfile generated by Ant's XMLLogger is over 130MB, which we just don't have the disk space to store too many copies of.

There is a way you can have the best of both worlds (sort of). Try this in your cruisecontrol.xml configuration file:

   <schedule>
      <ant antWorkingDir="/path/to/your/workspace"
           anthome="/path/to/your/ant/installation
           target="-lib /etc/cruisecontrol/buildX-settings:/opt/cruisecontrol/lib/log4j.jar -listener org.apache.tools.ant.listener.Log4jListener build"
           uselogger="true"/>
      </ant>
    <schedule>

IMPORTANT: Notice how we're passing arbitary ant parameters in the "target" attribute? This is because this attribute (as of CC 2.3.1) is simply appended to the end of the Ant command line. To get this to work properly, you probably need to either use the "anthome", or "antscript" attributes,
otherwise the command line for Ant is constructed in a different way (see http://cvs.sourceforge.net/viewcvs.py/cruisecontrol/cruisecontrol/main/src/net/sourceforge/cruisecontrol/builders/AntScript.java?rev=1.2&view=auto for exactly how it constructs the command line.

In /etc/cruisecontrol/buildX-settings, create a "log4j.properties" file that looks like this:

log4j.rootCategory=INFO,HUB

# HUB is a socket hub appender
log4j.appender.HUB=org.apache.log4j.net.TelnetAppender
log4j.appender.HUB.layout=org.apache.log4j.PatternLayout
log4j.appender.HUB.layout.ConversionPattern=[cc]%d{MMM-dd HH:mm:ss} %-14.14c{1}- %m%n
log4j.appender.HUB.port=9005

And presto!, you can now telnet in and watch your build as it goes. As per the example above, your log4j.properties file for Ant could also use the SocketHubAppender and you could connect to the build with Chainsaw.

Note that because this particular instance of log4j is only for your Ant build, the socket will only be alive while the build is in progress. However, the options with the log4j setup are almost limitless. For example, you could get Ant to push all the logmessages to a Jabber chatroom for example, and anyone interested simply needs to join the room.

Using this setup, you can keep your nice small sized log.xml files (from uselogger=true, and usequiet=true if you do that), but you can still have full access to your build messages, without wasting lots of disk space.

Powered by a free Atlassian Confluence Open Source Project / Non-profit License granted to ThoughtWorks, Inc.. Evaluate Confluence today.
Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators