Jump to: navigation, search

Swordfish Documentation: Turning On Logging

Revision as of 06:03, 12 November 2009 by Juergen.kindler.sopera.de (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to turn on logging for the Swordfish target platform

If you want to check why things go wrong at runtime your first choice would usually be turning on logging. Fortunately most components use the Apache Commons Logging that also adapts to the default java.utils.logging package. While it would also be possible to configure and use log4j, using the standard Java logging has the advantage that you do not have to add bundles to the target platform (and you get a sample that works here ;-) )

Create a logger.properties configuration

As the documentation of java.utils.logging is not very nice, see a few examples below.

A few notes about how the logging works:

  • Use the root logger level to set the global logging level (any logger that is not defined explicitly will get this level).
  • Use the handler specific level to specify the lowest level a logging handler will log.
  • If you set the log level for a specific package or class, make sure that the log level of your handler is at least on the same log level - otherwise the handler's log level will filter out the finer log entries.
  • If you don't set a formatter, you'll get XML by default.
  • Writing to files if only recommended on global scope or on class scope. If you use a filehandler on package scope, you'll get a log file for each logger in that package.

Example 1: Activate fine grained logging globally for Apache ServiceMix

handlers = java.util.logging.ConsoleHandler
# Set the default logging level for the root logger
.level = INFO

# Set the default logging level for new ConsoleHandler instances
java.util.logging.ConsoleHandler.level = ALL

# Set the default formatter for new ConsoleHandler instances
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

# Set the logging level for the loggers of package org.apache.servicemix
# Possible values: OFF (no logging) SEVERE (highest value), WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL
org.apache.servicemix.level = FINEST

Example 2: Write everything to a shared log file

# Specify the handlers to create in the root logger
# (all loggers are children of the root logger)
# The following creates two handlers
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler

# Set the default logging level for the root logger
.level = INFO

# Show all messages on the console
java.util.logging.ConsoleHandler.level = ALL

# Use the SimpleFormatter to get readable output
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter


# Show all messages in the global log file
java.util.logging.FileHandler.level = ALL

# Set the log file name to be in the $HOME/temp folder with name pattern myLogName*.log
java.util.logging.FileHandler.pattern = %h/temp/myLogName%u.log

# Use the SimpleFormatter to get readable output
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter

Pass the path of a log configuration file to Java

All you have to do is set a system property when you start your Swordfish instance and start it.

-Djava.util.logging.config.file={yourPathToConfigFile}/logger.properties