Introduction
...
Code Block |
---|
public JobSupervisor(Provider<JobDAO> jobDaoProvider, Provider<Long> jobTimeoutProvider) { |
The Provider<X> interface provides a get() method returning X. This allows for lazy initialization and/or providing an unknown number of X'es.
Further reading:
- http://www.vogella.com/tutorials/DependencyInjection/article.html
- http://square.github.io/dagger/
- http://www.infoq.com/presentations/Dagger
...
JavaDoc is strongly encouraged, as the code might explain what happens, but not the why; the JavaDoc must describe the intent of the function, including assumptions and invariants as well as expectations of the arguments. Please add and improve as needed.
Logging
We use the apache.commons.logging framework for logging (currently version 1.0.4), which gives us one unified interface that can be realized with different underlying systems.
However, currently the monitoring component requires the underlying implementation to be Jdk14 logging, since it exposes log messages using a LogHandler implementation for the Jdk14 framework. To use another logging framework, this method would need to be redefined for that framework (for instance an appender for Log4J).
Getting a logger
Retrieving an logger is a straightforward matter. Each class uses the logger interface to obtain a logger, using the class name to identify the logger.
Code Block |
---|
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class MyClass {
// A named logger for this class is retrieved
protected final Log log LogFactory.getLog(getClass());
}
|
Using the logger
Logging messages are generated using the level specific logging methods:
- log.fatal("Error situations where the application can not recover" ,Throwable);
- log.error
- log.warn("Error situations where the application may continue to operate" ,Throwable);
- log.info("Information about major modules/functionalities. Like Application data loaded, Application services started. also used, where log.config() was used before" ,Throwable)
- log.debug("Major functionalities within individual packages and classes are reported; Also used for tracing. Information within each method may be displayed" ,Throwable)
- log.trace("Detailed tracing information" ,Throwable)
See http://jakarta.apache.org/commons/logging/guide.html#Logging_a_Message
When we used java.util.logging, we used these levels
- logger.severe("Error situations where the application can not recover")
- logger.warning("Error situations where the application may continue to operate")
- logger.info("Information about major modules/functionalites. Like Application data loaded, Application services started")
- logger.config("Only used to report application configuration information")
- logger.fine("Major functionalities within indvidual packages and classes are reported")
- logger.finer("Used for tracing. Information within each method may be displayed")
- logger.finest("Detailed tracing information")
- logger.log( FINER, "Exception logging", exception)
...
.
...
Logger configuration
The logging levels and handlers are defined using a configuration filelog.prop=. The loglevels mentioned in this configuration file uses loglevels defined by java.util.logging.Level
An example file:
Code Block |
---|
#define handler(s)
handlers=java.util.logging.FileHandler
#define default logging level
.level=INFO
#setup the file handler
java.util.logging.FileHandler.pattern=java%g.log
java.util.logging.FileHandler.limit=100000
java.util.logging.FileHandler.count=3
java.util.logging.FileHandler.formatter=java.util.logging.XMLFormatter
#define logging levels
dk.netarkivet.level=WARNING
dk.netarkivet.demo.MyClass.level=ALL
|
In order to load the configuration file add the following to the java command lines:
...