Sun Java System Instant Messaging 7.2 Administration Guide

Managing Instant Messaging Logging Using Log4j

When you install Instant Messaging, a template file (log4j.conf.template) for the log4j configuration file is installed into the im-svr-base/lib directory. When you run the configure utility after installation, the template is used to create the log4j configuration file (log4j.conf) in the im-cfg-base directory. This configuration file is used to determine where to store log files generated by log4j, the logging level to use for various components, the output syntax, and to determine what log files to generate.

This section describes using the log4j logger to generate log files for Instant Messaging in the following sections:

The logging levels described in Instant Messaging Component Logging Levels are used by the log4j logger.

For more information about log4j, and instructions on configuring aspects of log files, such as size, number of backups, etc., see the Apache Logging Services website.

Instant Messaging Log4j Configuration File (log4j.conf) Location

You can change the location of the log4j configuration file, log4j.conf, by modifying the iim.log4j.config parameter in iim.conf. If you do not specify a value for this parameter, the logger will look in im-cfg-base. If the logger does not find the log4j configuration file in that directory, it uses the logging parameters in iim.conf to generate non-log4j style logs.

See Instant Messaging Server Directory Structure for information on locating im-cfg-base.

Instant Messaging Log4j Log File Syntax

The configure utility generates the log4j configuration file (log4j.conf) based on the content of the log4j configuration file template (log4j.conf.template). Example 13–1 shows the log4j template. In this template:


Example 13–1 Log4j Template File


log4j.logger.xmppd=INFO, A1
# DEFAULT TO RollingFileAppender
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.file=${logdir}/xmppd.log
log4j.appender.A1.append=true
log4j.appender.A1.maxBackupIndex=7
log4j.appender.A1.maxFileSize=5mb
# More example appenders..
# Straight to console..
# log4j.appender.A1=org.apache.log4j.ConsoleAppender
# log4j.appender.A1.ImmediateFlush=true
# Rollover at midnight..
# log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
# log4j.appender.A1.DatePattern='.'yyyy-MM-dd
# log4j.appender.A1.file=${logdir}/xmppd.log
# log4j.appender.A1.ImmediateFlush=true
# log4j.appender.A1.append=true
# Send to SMTP..
# log4j.appender.A1=org.apache.log4j.SMTPAppender

# PATTERN LAYOUT AND OPTIONS
# DEFAULT TO PatternLayout
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
# For full dates..
log4j.appender.A1.layout.ConversionPattern=[%d{DATE}] %-5p %c [%t] %m%n
# IM traditional output format..
#log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p %c [%t] %m%n
# More example layouts
# XMLLayout for chainsaw consumption
# log4j.appender.A1.layout=org.apache.log4j.xml.XMLLayout
# TTCCLayout for NDC information

# log4j.appender.A1.layout=org.apache.log4j.xml.TTCCLayout
# log4j.appender.A1.layout.DateFormat=ISO8601
# log4j.appender.A1.layout.TimeZoneID=GMT-8:00
# log4j.appender.A1.layout.CategoryPrefixing=false
# log4j.appender.A1.layout.ThreadPrinting=false
# log4j.appender.A1.layout.ContextPrinting=false

# Now we list logger/appender/layout for the other default loggers, but
# only the defaults..
log4j.logger.iim_wd=ERROR, A2
log4j.appender.A2=org.apache.log4j.RollingFileAppender
log4j.appender.A2.file=${logdir}/iim_wd.log
log4j.appender.A2.append=true
log4j.appender.A2.maxBackupIndex=7
log4j.appender.A2.maxFileSize=5mb
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=[%d{DATE}] %-5p %c [%t] %m%n

# For separate xmpp traffic log, disabled by default.
log4j.logger.xmppd.xfer=DEBUG, A3
log4j.appender.A3=org.apache.log4j.varia.NullAppender
# Select next block instead of previous line to enable separate transfer log
# log4j.appender.A3=org.apache.log4j.RollingFileAppender
# log4j.appender.A3.file=${logdir}/xfer.log
# log4j.appender.A3.append=true
# log4j.appender.A3.maxBackupIndex=7
# log4j.appender.A3.maxFileSize=5mb
# log4j.appender.A3.layout=org.apache.log4j.PatternLayout
# # Note, simpler default output than above 3 loggers:
# log4j.appender.A3.layout.ConversionPattern=[%d{DATE}] %-5p %c [%t] %m%n

log4j.logger.agent-calendar=ERROR, A4
log4j.appender.A4=org.apache.log4j.RollingFileAppender
log4j.appender.A4.file=${logdir}/agent-calendar.log
log4j.appender.A4.append=true
log4j.appender.A4.maxBackupIndex=7
log4j.appender.A4.maxFileSize=5mb
log4j.appender.A4.layout=org.apache.log4j.PatternLayout
log4j.appender.A4.layout.ConversionPattern=[%d{DATE}] %-5p %c [%t] %m%n

log4j.logger.net.outer_planes.jso.BasicStream=OFF, A5
log4j.appender.A5=org.apache.log4j.RollingFileAppender
log4j.appender.A5.file=${logdir}/jso.log
log4j.appender.A5.append=true
log4j.appender.A5.maxBackupIndex=7
log4j.appender.A5.maxFileSize=5mb
log4j.appender.A5.layout=org.apache.log4j.PatternLayout
log4j.appender.A5.layout.ConversionPattern=[%d{DATE}] %-5p %c [%t] %m%n

log4j.logger.genredirect=INFO, A6
log4j.appender.A6=org.apache.log4j.RollingFileAppender
log4j.appender.A6.file=${logdir}/genredirect.log
log4j.appender.A6.append=true
log4j.appender.A6.maxBackupIndex=7
log4j.appender.A6.maxFileSize=5mb
log4j.appender.A6.layout=org.apache.log4j.PatternLayout
log4j.appender.A6.layout.ConversionPattern=[%d{DATE}] %-5p %c [%t] %m%n

Log4j Log Levels for Instant Messaging Components

The log4j logger uses the same logging levels described for the iim.conf parameter-based logging mechanism in Instant Messaging Component Logging Levels.

ProcedureTo Specify the Location of the Log4j Configuration File (Log4j.conf)

  1. Open iim.conf.

    See iim.conf File Location for information on locating this file.

  2. Set the iim.log4j.config parameter to the path in which you want the logger to look for log4j.conf.

    For example, on Solaris:


    iim.log4j.config=/etc/opt/SUNWiim/default/config/log4j.conf
    

    On Linux:


    iim.log4j.config=/etc/opt/sun/im/default/config/log4j.conf
    
  3. Save and close iim.conf.

  4. Refresh the server.


    imadmin refresh
    

ProcedureTo Enable or Disable Log4j Logging for an Instant Messaging Component

By default, log4j logging is used for all components for which logging information is generated.

  1. To disable log4j logging, set the logging level for the component to OFF in both log4j.conf and log4j.conf.template.

    See To Set Log4j Log Levels for Instant Messaging for more information.

  2. To enable log4j logging, set the logging level for the component to any logging level other than OFF in both log4j.conf and log4j.conf.template.

ProcedureTo Set Log4j Log Levels for Instant Messaging

You can set log levels by modifying either the template or the log configuration file. However, if you only modify the configuration file, any changes you make will be overwritten the next time you run configure. To prevent this, you should make your changes to both the configuration file and the template.

  1. Open log4j.conf.template.

    By default, this file is stored in the following location:


    im-svr-base/lib
  2. For each component, specify the logging level you want to use.

    For example, to set the log level for the server:


    log4j.logger.xmppd=log-level
    

    Where log-level is one of FATAL, ERROR, WARNING, INFO, or DEBUG.

    See Table 13–1 for detailed information on each of these logging levels.

  3. Save and close log4j.conf.template.

  4. Repeat the procedure for the configuration file log4j.conf.

ProcedureTo Specify the Maximum Log4j Log File Size for Instant Messaging Components

You can set log levels by modifying either the template or the log configuration file. However, if you only modify the configuration file, any changes you make will be overwritten the next time you run configure. To prevent this, you should make your changes to both the configuration file and the template.

  1. Open log4j.conf.template.

    By default, this file is stored in the following location:


    im-svr-base/lib
  2. For each component, specify the maximum size for the component's log file.

    For example, to set the size for the server log file:


    log4j.appender.A1.maxFileSize=max-logfile-size
    

    Where A1 is the default appender ID for the server, max-logfile-size is in MB, for example 5MB.

  3. Repeat the procedure for the configuration file log4j.conf.