Skip to main content

Notice: This Wiki is now read only and edits are no longer 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"

(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...)
 
Line 1: Line 1:
= How to turn on logging for the Swordfish target platform<br> =
+
= 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 most components use the [http://commons.apache.org/logging/index.html Apache Commons Logging] that also adapts to the default [http://java.sun.com/javase/6/docs/api/java/util/logging/package-summary.html 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&nbsp;;-) )<br>
+
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 [http://commons.apache.org/logging/index.html Apache Commons Logging] that also adapts to the default [http://java.sun.com/javase/6/docs/api/java/util/logging/package-summary.html 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&nbsp;;-) )
  
== Steps to influence the log output<br> ==
+
== Create a logger.properties configuration ==
  
=== Create a logger.properties configuration ===
+
As the documentation of java.utils.logging is not very nice, see a few examples below.<br>
  
As the documentation of java.utils.logging is not very nice, see a few examples below.<br>
+
A few notes about how the logging works:
  
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.
  
*Use the root logger level to set the global logging level (any logger that is not defined explicitly will get this level).
+
=== Example 1: Activate fine grained logging globally for Apache ServiceMix<br> ===
*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<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
Line 30: Line 28:
 
# Set the default logging level for the loggers
 
# Set the default logging level for the loggers
 
# 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> ===
 
<pre># Specify the handlers to create in the root logger
 
<pre># Specify the handlers to create in the root logger
 
# (all loggers are children of the root logger)
 
# (all loggers are children of the root logger)
Line 46: Line 44:
 
'''# Set the default logging level for new FileHandler instances
 
'''# Set the default logging level for new FileHandler instances
 
java.util.logging.FileHandler.level = ALL
 
java.util.logging.FileHandler.level = ALL
java.util.logging.FileHandler.pattern = %h/temp/myLogName%u.log
+
java.util.logging.FileHandler.pattern =&nbsp;%h/temp/myLogName%u.log
 
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter'''
 
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter'''
  
</pre>
+
</pre>  
=== Pass the path of a log configuration file to Java<br>  ===
+
== Pass the path of a log configuration file to Java<br>  ==
  
All you have to do is set a system property when you start your Swordfish instance and start it.
+
All you have to do is set a system property when you start your Swordfish instance and start it.  
<pre>-Djava.util.logging.config.file={yourPathToConfigFile}/logger.properties</pre>
+
<pre>-Djava.util.logging.config.file={yourPathToConfigFile}/logger.properties</pre>  
 
<br>
 
<br>

Revision as of 05:52, 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 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