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

Scout/HowTo/3.7/Setup different Log-Configuration for Production and Development

< Scout‎ | HowTo‎ | 3.7

The Scout documentation has been moved to https://eclipsescout.github.io/.

When using eclipse log, things are described in the eclipse log manual (XXX where?).

When using java log, by default the jre's logging.properties in the jre/lib folder are used. For server-side equinox applications the logging config should be left to the application server.

For client applications there is the system property -Djava.util.logging.config.class= 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).

  1. Create a fragment to the system.bundle that contains various log config classes.
  2. Add the fragment to the product configurations
  3. 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

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


Dev.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"));
	}
}

Dev.properties

### 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

System/Launching property:

-Djava.util.logging.config.class=com.myapp.logger.Dev


DevFine.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"));
	}
}

DevFine.properties

### 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

System/Launching property:

-Djava.util.logging.config.class=com.myapp.logger.DevFine


Prod.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"));
	}
}

Prod.properties

### 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

System/Launching property:

-Djava.util.logging.config.class=com.myapp.logger.Prod

Back to the top