|
|
Line 1: |
Line 1: |
− | {{ScoutPage|cat=HowTo 4.0}}
| + | The Scout documentation has been moved to https://eclipsescout.github.io/. |
− | == Introduction ==
| + | |
− | When using Eclipse Log, things are described in the Eclipse Log manual.
| + | |
− | | + | |
− | When using java log, by default the JRE's logging.properties in the jre/lib folder is used.
| + | |
− | For server-side Equinox applications the logging config should be left to the application server.
| + | |
− | | + | |
− | For client applications there is the system property <code>-Djava.util.logging.config.class</code> that can be used.
| + | |
− | This system property can be set in the product configuration's "Launching" tab and can be set to alternative
| + | |
− | configuration classes in each product (dev, test, production).
| + | |
− | | + | |
− | # Create a fragment to the system.bundle that contains various log config classes.
| + | |
− | # Add the fragment to your product configurations
| + | |
− | # set the -Djava.util.logging.config.class=.... accordingly
| + | |
− | | + | |
− | == Example fragment com.myapp.logger.fragment ==
| + | |
− | Make sure to put these files into the same package and export the package in the manifest (unexported packages lead to ClassNotFoundException!)
| + | |
− | | + | |
− | MANIFEST.MF
| + | |
− | <pre>
| + | |
− | Manifest-Version: 1.0
| + | |
− | Bundle-ManifestVersion: 2
| + | |
− | Bundle-Name: Logger Configurations
| + | |
− | Bundle-SymbolicName: com.myapp.logger.fragment
| + | |
− | Bundle-Version: 1.0.0.qualifier
| + | |
− | Fragment-Host: system.bundle
| + | |
− | Bundle-RequiredExecutionEnvironment: JavaSE-1.6
| + | |
− | Export-Package: com.myapp.logger
| + | |
− | </pre>
| + | |
− | | + | |
− | | + | |
− | Dev.java
| + | |
− | <source lang="java">
| + | |
− | package com.myapp.logger;
| + | |
− | import java.util.logging.LogManager;
| + | |
− | | + | |
− | | + | |
− | public class Dev {
| + | |
− | public Dev() throws Exception{
| + | |
− | System.out.println("Loading logger configuration: "+getClass());
| + | |
− | LogManager.getLogManager().readConfiguration(getClass().getResourceAsStream(getClass().getSimpleName()+".properties"));
| + | |
− | }
| + | |
− | }
| + | |
− | </source>
| + | |
− | | + | |
− | Dev.properties
| + | |
− | <pre>
| + | |
− | ### Root level (do NOT set the root level to INFO, use the custom levels below)
| + | |
− | .level= WARNING | + | |
− | | + | |
− | ### Handlers
| + | |
− | handlers= java.util.logging.ConsoleHandler
| + | |
− | | + | |
− | ### Handler properties
| + | |
− | # you have to set a value for the ConsoleHandler or otherwise it will set the Level INFO as default
| + | |
− | # and ignore all other levels
| + | |
− | java.util.logging.ConsoleHandler.level=ALL
| + | |
− | </pre>
| + | |
− | | + | |
− | System/Launching property:
| + | |
− | <pre>
| + | |
− | -Djava.util.logging.config.class=com.myapp.logger.Dev
| + | |
− | </pre>
| + | |
− | | + | |
− | | + | |
− | DevFine.java
| + | |
− | <source lang="java">
| + | |
− | package com.myapp.logger;
| + | |
− | import java.util.logging.LogManager;
| + | |
− | | + | |
− | | + | |
− | public class DevFine {
| + | |
− | public DevFine() throws Exception{
| + | |
− | System.out.println("Loading logger configuration: "+getClass());
| + | |
− | LogManager.getLogManager().readConfiguration(getClass().getResourceAsStream(getClass().getSimpleName()+".properties"));
| + | |
− | }
| + | |
− | }
| + | |
− | </source>
| + | |
− | | + | |
− | DevFine.properties
| + | |
− | <pre>
| + | |
− | ### Root level (do NOT set the root level to INFO, use the custom levels below)
| + | |
− | .level= WARNING
| + | |
− | | + | |
− | ### Handlers
| + | |
− | handlers= java.util.logging.ConsoleHandler
| + | |
− | | + | |
− | ### Handler properties
| + | |
− | # you have to set a value for the ConsoleHandler or otherwise it will set the Level INFO as default
| + | |
− | # and ignore all other levels
| + | |
− | java.util.logging.ConsoleHandler.level=ALL
| + | |
− | | + | |
− | ### Custom log levels
| + | |
− | com.myapp.server.online.services.common.sql.SqlService.level=INFO
| + | |
− | </pre>
| + | |
− | | + | |
− | System/Launching property:
| + | |
− | <pre>
| + | |
− | -Djava.util.logging.config.class=com.myapp.logger.DevFine
| + | |
− | </pre>
| + | |
− | | + | |
− | | + | |
− | Prod.java
| + | |
− | <source lang="java">
| + | |
− | package com.myapp.logger;
| + | |
− | import java.util.logging.LogManager;
| + | |
− | | + | |
− | | + | |
− | public class Prod {
| + | |
− | public Prod() throws Exception{
| + | |
− | System.out.println("Loading logger configuration: "+getClass());
| + | |
− | LogManager.getLogManager().readConfiguration(getClass().getResourceAsStream(getClass().getSimpleName()+".properties"));
| + | |
− | }
| + | |
− | }
| + | |
− | </source>
| + | |
− | | + | |
− | Prod.properties
| + | |
− | <pre>
| + | |
− | ### Root level (do NOT set the root level to INFO, use the custom levels below)
| + | |
− | .level= WARNING
| + | |
− | | + | |
− | ### Handlers
| + | |
− | handlers= java.util.logging.FileHandler
| + | |
− | | + | |
− | ### Handler properties
| + | |
− | # .pattern is the log file path, this default here outputs in user's home directory
| + | |
− | java.util.logging.FileHandler.pattern = %h/my-log%u.log
| + | |
− | java.util.logging.FileHandler.limit = 100000000
| + | |
− | java.util.logging.FileHandler.count = 10
| + | |
− | java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
| + | |
− | | + | |
− | ### Custom log levels
| + | |
− | </pre>
| + | |
− | | + | |
− | System/Launching property:
| + | |
− | <pre>
| + | |
− | -Djava.util.logging.config.class=com.myapp.logger.Prod
| + | |
− | </pre>
| + | |
− | | + | |
− | == See Also ==
| + | |
− | *[[{{BASEPAGENAME}}/Create_a_CustomLogManager_for_log4j|Create a CustomLogManager for Log4J]]
| + | |
− | *[[{{BASEPAGENAME}}/Make_use_of_the_additional_Scout_logging_features|Make use of the additional Scout logging features]]
| + | |