Customizing the output of logging messages from the debugger

To create a customized log4j configuration file:

  1. Create an Appender instance for the required logging type. The following types are supported:

    • ConsoleAppender

    • RollingFileAppender.

  2. Suppress the Threshold logging level, if required.

  3. If the Appender instance outputs to a file, define the layout for the Appender instance. The following layouts are supported:

    PatternLayout

    Textual format.

    HTMLLayout

    HTML format.

  4. If the Appender instance outputs to a file, define the file components. The following components are supported:

    File

    File name

    MaxFileSize

    Long integer or string, 10KB.

    MaxBackupIndex

    Maximum number of log files to use. The default is 1.

  5. If you use the layout PatternLayout, you can enhance the format of a message by using an additional ConversionPattern component. The following patterns are supported:

    %c

    Logging category

    %C

    Class name

    %d

    Date

    %F

    Filename

    %l

    Caller location

    %L

    Line number

    %m

    Logging message

    %M

    Method name

    %n

    End of line character

    %p

    Logging level. For alignment, you can also supply the number of characters, for example: %-5p.

    %r

    Elapsed time (milliseconds)

    %t

    Thread name.

  6. Define the name component for the Appender instance, if required.

  7. Define the logging level for the rootLogger and assign to the required Appender instance.

  8. To pass the log4j configuration file to the debugger you can use:

    • --log_config=filename command-line option when launching the debugger from the command-line console.

    • log config filename debugger command if the debugger is already running.

Show/hideExample showing how to log messages to the console

The following example shows how to log messages to the console. This sets the default logging level to DEBUG. All the logging for this example is output to the console. However the output of error and warning messages are sent to the error stream, and debug and info messages are sent to the output stream.

Example 8. Logging messages to the console

# Setup logConsole to be a ConsoleAppender
log4j.appender.logConsole=org.apache.log4j.ConsoleAppender
log4j.appender.logConsole.layout=org.apache.log4j.PatternLayout
log4j.appender.logConsole.layout.ConversionPattern=%m%n
log4j.appender.logConsole.name=Console

# Send all DEBUG level logs to the console
log4j.rootLogger=DEBUG, console

Show/hideExample showing how to log messages to a file

The following example shows how to log messages to a file. This sets the default logging level to DEBUG. However some packages only write logs at the INFO level. All the logging for this example is output to a file. When the file reaches 10MB, it is renamed by adding .1 file extension and logging continues to write to a new file with the original name. This happens multiple times, but only ten backup files are stored.

Example 9. Logging messages to a file

# Setup logFile to be a RollingFileAppender
log4j.appender.logFile=org.apache.log4j.RollingFileAppender
log4j.appender.logFile.File=output.log
log4j.appender.logFile.MaxFileSize=10MB
log4j.appender.logFile.MaxBackupIndex=10
log4j.appender.logFile.layout=org.apache.log4j.PatternLayout
log4j.appender.logFile.layout.ConversionPattern=%d %-5p %t %c - %m%n

# Send all DEBUG level logs to a file: logFile
log4j.rootLogger=DEBUG, logFile

# Send all INFO level logs in the debug packages to the file: logFile
log4j.logger.com.arm.debug.logging=INFO, logFile

Show/hideExample showing how to combine the logging of messages to the console and a file

The following example shows a combination of the previous examples. This sets the default logging level to INFO. All the INFO level logging for this example is output to the console. However, a selection of messages are also sending output to two files.

Example 10. Combination of logging messages

# Setup logConsole to be a ConsoleAppender
log4j.appender.logConsole=org.apache.log4j.ConsoleAppender
# Suppress all logs to the console that are lower than the threshold
log4j.appender.logConsole.Threshold=INFO
log4j.appender.logConsole.layout=org.apache.log4j.PatternLayout
log4j.appender.logConsole.layout.ConversionPattern=%m%n
log4j.appender.logConsole.name=Console

# Setup logConnFile to be a RollingFileAppender
log4j.appender.logConnFile=org.apache.log4j.RollingFileAppender
# Suppress all logs to the file that are lower than the threshold
log4j.appender.logConnFile.Threshold.DEBUG
log4j.appender.logConnFile.File=connection.log
log4j.appender.logConnFile.MaxFileSize=10MB
log4j.appender.logConnFile.MaxBackupIndex=10
log4j.appender.logConnFile.layout=org.apache.log4j.PatternLayout
log4j.appender.logConnFile.layout.ConversionPattern=%d %-5p %t %c - %m%n

# Setup logTAccessFile to be a RollingFileAppender
log4j.appender.logTAccessFile=org.apache.log4j.RollingFileAppender
# Suppress all logs to the file that are lower than the threshold
log4j.appender.logTAccessFile.Threshold.DEBUG
log4j.appender.logTAccessFile.File=target_acccess.log
log4j.appender.logTAccessFile.MaxFileSize=10MB
log4j.appender.logTAccessFile.MaxBackupIndex=10
log4j.appender.logTAccessFile.layout=org.apache.log4j.PatternLayout
log4j.appender.logTAccessFile.layout.ConversionPattern=%d %-5p %t %c - %m%n

# Send all INFO logs to the console
log4j.rootLogger=INFO, logConsole

# Send all DEBUG logs in the connection package to the file: logConnFile
log4j.logger.com.arm.debug.core.engine.connection=DEBUG, logConnFile

# Send all DEBUG logs in the targetaccess package to the file: logTAccessFile
log4j.logger.com.arm.debug.core.targetaccess.rvi=DEBUG, logTAccessFile

Show/hideSee also

Copyright © 2010-2012 ARM. All rights reserved.ARM DUI 0446K
Non-ConfidentialID071912