Logging

For logging we use slf4j.

Example taken from: http://www.slf4j.org/manual.html  1: import org.slf4j.Logger;
2: import org.slf4j.LoggerFactory;
3:
4: public class Wombat {
5:
6: final Logger logger = LoggerFactory.getLogger(Wombat.class);
7: Integer t;
8: Integer oldT;
9:
10: public void setTemperature(Integer temperature) {
11:
12: oldT = t;
13: t = temperature;
14:
15: logger.debug("Temperature set to {}. Old temperature was {}.", t, oldT);
16:
17: if(temperature.intValue() > 50) {
18: logger.info("Temperature has risen above 50 degrees.");
19: }
20: }
21: }
The example makes use of the printf-style feature of slf4j, instead of logger.debug("Temperature set to " t". Old temperature was "oldT".")
logger.debug("Temperature set to {}. Old temperature was {}.", t, oldT) is used, the latter prevents the string being concatenated id the concatenation is not needed (e.g. because debug-level messages are not logged).

Labels

 
(None)