1 18 19 20 import org.objectweb.util.monolog.Monolog; 21 import org.objectweb.util.monolog.api.BasicLevel; 22 import org.objectweb.util.monolog.api.Logger; 23 import org.objectweb.util.monolog.api.LoggerFactory; 24 25 26 31 public class Simple { 32 public static void main(String[] args) { 33 LoggerFactory lf; 34 switch(args.length) { 35 case 0: 36 lf = Monolog.initialize(); 39 break; 40 case 1: 41 lf = Monolog.getMonologFactory(args[0]); 43 break; 44 default: 45 System.out.println("Syntax error!\nUsage: java Simple [<monolog file name>]"); 46 return; 47 } 48 Simple s = new Simple(lf); 49 s.foo(); 50 s.bar(); 51 } 52 53 private static final boolean DEBUG = false; 54 55 protected Logger logger = null; 56 57 public Simple(LoggerFactory lf) { 58 logger = lf.getLogger("monolog.examples.Simple"); 59 } 60 61 public void foo() { 62 if (logger.isLoggable(BasicLevel.DEBUG)) { 63 logger.log(BasicLevel.DEBUG, 64 "my logger has been configured in order to log debug message"); 65 } 66 logger.log(BasicLevel.INFO, "foo : hello my favourite logger in info"); 67 68 if (DEBUG && logger.isLoggable(BasicLevel.DEBUG)) { 69 logger.log(BasicLevel.DEBUG, "This message should not appears"); 72 } 73 } 74 75 public void bar() { 76 logger.log(BasicLevel.WARN, "bar : warning !"); 77 logger.log(BasicLevel.ERROR, "This is a throwed exception", 78 new Throwable().fillInStackTrace()); 79 } 80 } 81 | Popular Tags |