Logging with SLF4J
From JQuantLib
Contents |
Introduction
In JQuantlib we use the SLF4J logging framework (an abstraction layer for the concrete logging implementation).
Usage
Get a logger
As usual get a static Logger from the LoggerFactory
final static Logger logger = LoggerFactory.getLogger(ThisClass.class);
Note: Using a static logger has three main consequences:
- It is faster (compared to non-static)
- You don't have to care about potential serialization issues
- BUT: YOU MAY GET SEVERE CLASSLOADER PROBLEMS (eg. in JEE servers)
Use the logger
Using SLF4J you don't have to guard your logging statements any longer. To avoid the evaluation of expressions, when logging is disabled (on the respective level) you have to use parameterized logging. I.e.
logger.debug("The entry is {}.", entry);
the {} will be substituted by entry if logging on the respective level is in fact enabled. The substitution mechanism works for up to two objects (when more substitutions are required, you can use an array, check the apidoc ).

