Download Guide - Warework

Transcript
112
lead the application to abort.
To simplify the usage of the Logger, we will use the Console Logger with the levels defined at
LogServiceConstants class:
<sample-code:java>
// Remember always to connect the Logger first.
logService.connect("console-logger");
// Log a message using the console output.
logService.log("console-logger", "Log this message in the console",
LogServiceConstants.LOG_LEVEL_Info);
</sample-code:end>
This example will show in the console output something like:
[INFO @ <scope-name>] Log this message in the console
Log4j Logger
Log4j Logger gives the possibility to perform log operations with Log4j in Warework. This is a
well-known and very stable Framework, used to log messages on multiple outputs like console,
text files and also databases. If you plan to have fine grained control of what is logged on each
output then Log4j is a very good choice.
Prior to work with this Logger, you should review the Log4j documentation, especially the section related with the configuration. There you will find how to define the target output for the logs
and how to format for them.
Add a Log4j Logger
To add a Log4j Logger into the Log Service you have to invoke method createClient() that
exists in its Facade with a name, a Log4j Connector class and a configuration for the Logger.
You can use two different kinds of Connectors. If you plan to configure Log4j with a properties
file, then you should use Log4jPropertiesConnector as follows:
<sample-code:java>
// Create the configuration for the Logger.
Hashtable config = new Hashtable();
// Set the location of the Log4j configuration file.
config.put(Log4jPropertiesConnector.PARAMETER_ConfigTarget,
"/META-INF/system/log4j.properties");
// Create the Log4j Logger.
logService.createClient("log4j-logger",
Log4jPropertiesConnector.class, config);
</sample-code:end>
The Log4jPropertiesConnector collects the configuration and sets up a Log4j Logger with
the properties file that exists where PARAMETER_ConfigTarget specifies. Please review in
the Log4j documentation how to configure Log4j with properties files. Check it now how to do it
with the Proxy Service XML configuration file: