View Javadoc
1   /**
2    *    Copyright 2006-2016 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.generator.logging;
17  
18  import java.util.logging.Level;
19  import java.util.logging.LogRecord;
20  import java.util.logging.Logger;
21  
22  /**
23   * 
24   * @author Clinton Begin
25   * @author Jeff Butler
26   * 
27   */
28  public class JdkLoggingImpl implements Log {
29  
30      private Logger log;
31  
32      public JdkLoggingImpl(Class<?> clazz) {
33          log = Logger.getLogger(clazz.getName());
34      }
35  
36      public boolean isDebugEnabled() {
37          return log.isLoggable(Level.FINE);
38      }
39  
40      public void error(String s, Throwable e) {
41          LogRecord lr = new LogRecord(Level.SEVERE, s);
42          lr.setSourceClassName(log.getName());
43          lr.setThrown(e);
44  
45          log.log(lr);
46      }
47  
48      public void error(String s) {
49          LogRecord lr = new LogRecord(Level.SEVERE, s);
50          lr.setSourceClassName(log.getName());
51  
52          log.log(lr);
53      }
54  
55      public void debug(String s) {
56          LogRecord lr = new LogRecord(Level.FINE, s);
57          lr.setSourceClassName(log.getName());
58  
59          log.log(lr);
60      }
61  
62      public void warn(String s) {
63          LogRecord lr = new LogRecord(Level.WARNING, s);
64          lr.setSourceClassName(log.getName());
65  
66          log.log(lr);
67      }
68  }