Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Swordfish Documentation: Turning On Logging

Revision as of 05:51, 12 November 2009 by Juergen.kindler.sopera.de (Talk | contribs) (New page: = How to turn on logging for the Swordfish target platform<br> = If you want to check why things go wrong at runtime your first choice would usually be turning on logging. Fortunately mos...)

(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 ;-) )

Steps to influence the log output

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 default logging level for the loggers
# 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

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


'''# Set the default logging level for new FileHandler instances
java.util.logging.FileHandler.level = ALL
java.util.logging.FileHandler.pattern = %h/temp/myLogName%u.log
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


Back to the top