View Javadoc

1   /*
2    * JavaLoggingLog.java
3    *
4    * Created on April 14, 2005, 4:28 PM
5    */
6   
7   package net.sf.asterisk.util.impl;
8   
9   import java.util.logging.Level;
10  import java.util.logging.Logger;
11  
12  import net.sf.asterisk.util.Log;
13  
14  /***
15   * Log implementation that uses the java.util.logging package.
16   * 
17   * @author drach
18   */
19  public class JavaLoggingLog implements Log
20  {
21      /***
22       * The underlying commons-logging Log object to use.
23       */
24      private Logger log;
25  
26      /***
27       * Creates a new JavaLoggingLog obtained from java.util.logging for the
28       * given class.
29       * 
30       * @param clazz the class to log for.
31       */
32      public JavaLoggingLog(Class clazz)
33      {
34          log = Logger.getLogger(clazz.getName());
35      }
36  
37      public void debug(Object obj)
38      {
39          log.fine(obj.toString());
40      }
41  
42      public void info(Object obj)
43      {
44          log.info(obj.toString());
45      }
46  
47      public void warn(Object obj)
48      {
49          log.warning(obj.toString());
50      }
51  
52      public void warn(Object obj, Throwable ex)
53      {
54          log.log(Level.WARNING, obj.toString(), ex);
55      }
56  
57      public void error(Object obj)
58      {
59          log.severe(obj.toString());
60      }
61  
62      public void error(Object obj, Throwable ex)
63      {
64          log.log(Level.SEVERE, obj.toString(), ex);
65      }
66  }