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

Difference between revisions of "Swordfish Documentation: Turning On Logging"

(Example 2: Write everything to a shared log file)
 
(5 intermediate revisions by the same user not shown)
Line 16: Line 16:
  
 
=== Example 1: Activate fine grained logging globally for Apache ServiceMix<br>  ===
 
=== Example 1: Activate fine grained logging globally for Apache ServiceMix<br>  ===
<pre>handlers = java.util.logging.ConsoleHandler
+
<pre>
 +
handlers = java.util.logging.ConsoleHandler
 
# Set the default logging level for the root logger
 
# Set the default logging level for the root logger
 
.level = INFO
 
.level = INFO
Line 26: Line 27:
 
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
 
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
  
# Set the default logging level for the loggers
+
# 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
 
# Possible values: OFF (no logging) SEVERE (highest value), WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL
org.apache.servicemix.level = FINEST</pre>
+
org.apache.servicemix.level = FINEST
 +
</pre>
  
 
=== Example 2: Write everything to a shared log file<br>  ===
 
=== Example 2: Write everything to a shared log file<br>  ===
Line 34: Line 36:
 
# (all loggers are children of the root logger)
 
# (all loggers are children of the root logger)
 
# The following creates two handlers
 
# The following creates two handlers
handlers = java.util.logging.ConsoleHandler''', java.util.logging.FileHandler'''
+
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler
 +
 
 
# Set the default logging level for the root logger
 
# Set the default logging level for the root logger
 
.level = INFO
 
.level = INFO
  
# Set the default logging level for new ConsoleHandler instances
+
# Show all messages on the console
 
java.util.logging.ConsoleHandler.level = ALL
 
java.util.logging.ConsoleHandler.level = ALL
 +
 +
# Use the SimpleFormatter to get readable output
 
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
 
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
  
  
'''# Set the default logging level for new FileHandler instances
+
# Show all messages in the global log file
 
java.util.logging.FileHandler.level = ALL
 
java.util.logging.FileHandler.level = ALL
java.util.logging.FileHandler.pattern =&nbsp;%h/temp/myLogName%u.log
 
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter'''
 
  
</pre>  
+
# 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
 +
</pre>
 +
 
 
== Pass the path of a log configuration file to Java<br>  ==
 
== Pass the path of a log configuration file to Java<br>  ==
  

Latest revision as of 06:03, 12 November 2009

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


Back to the top