| |||
| Home > Controlling runtime messages > Customizing the output of logging messages from the debugger | |||
To create a customized log4j configuration file:
Create an Appender instance for
the required logging type. The following types are supported:
ConsoleAppender
RollingFileAppender.
Suppress the Threshold logging
level, if required.
If the Appender instance outputs
to a file, define the layout for the Appender instance.
The following layouts are supported:
PatternLayoutTextual format.
HTMLLayoutHTML format.
If the Appender instance outputs
to a file, define the file components. The following components
are supported:
FileFile name
MaxFileSizeLong
integer or string, for example 10KB.
MaxBackupIndexMaximum number of log files to use. The default is 1.
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:
%cLogging category
%CClass name
%dDate
%FFilename
%lCaller location
%LLine number
%mLogging message
%MMethod name
%nEnd of line character
%pLogging
level. For alignment, you can also supply the number of characters, for
example: %-5p.
%rElapsed time (milliseconds)
%tThread name.
Define the name component for
the Appender instance, if required.
Define the logging level for the rootLogger and
assign to the required Appender instance.
To pass the log4j configuration file to the debugger you can use:
--log_config= command-line
option when launching the debugger from the command-line console.filename
log config debugger
command if the debugger is already running.filename
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 9. 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
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 10. 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
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 11. 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
ARM® DS-5™ Debugger Command Reference: