View Javadoc

1   // ========================================================================
2   // Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses.
12  // ========================================================================
13  
14  package org.eclipse.jetty.util.log;
15  
16  
17  
18  /**
19   * Slf4jLog Logger
20   */
21  public class Slf4jLog extends AbstractLogger
22  {
23      private final org.slf4j.Logger _logger;
24  
25      public Slf4jLog() throws Exception
26      {
27          this("org.eclipse.jetty.util.log");
28      }
29  
30      public Slf4jLog(String name)
31      {
32          //NOTE: if only an slf4j-api jar is on the classpath, slf4j will use a NOPLogger
33          org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger( name );
34          
35          // Fix LocationAwareLogger use to indicate FQCN of this class - 
36          // https://bugs.eclipse.org/bugs/show_bug.cgi?id=276670
37          if (logger instanceof org.slf4j.spi.LocationAwareLogger)
38          {
39              _logger = new JettyAwareLogger((org.slf4j.spi.LocationAwareLogger)logger);
40          }
41          else
42          {
43              _logger = logger;
44          }
45      }
46  
47      public String getName()
48      {
49          return _logger.getName();
50      }
51  
52      public void warn(String msg, Object... args)
53      {
54          _logger.warn(msg, args);
55      }
56  
57      public void warn(Throwable thrown)
58      {
59          warn("", thrown);
60      }
61  
62      public void warn(String msg, Throwable thrown)
63      {
64          _logger.warn(msg, thrown);
65      }
66  
67      public void info(String msg, Object... args)
68      {
69          _logger.info(msg, args);
70      }
71  
72      public void info(Throwable thrown)
73      {
74          info("", thrown);
75      }
76  
77      public void info(String msg, Throwable thrown)
78      {
79          _logger.info(msg, thrown);
80      }
81  
82      public void debug(String msg, Object... args)
83      {
84          _logger.debug(msg, args);
85      }
86  
87      public void debug(Throwable thrown)
88      {
89          debug("", thrown);
90      }
91  
92      public void debug(String msg, Throwable thrown)
93      {
94          _logger.debug(msg, thrown);
95      }
96  
97      public boolean isDebugEnabled()
98      {
99          return _logger.isDebugEnabled();
100     }
101 
102     public void setDebugEnabled(boolean enabled)
103     {
104         warn("setDebugEnabled not implemented",null,null);
105     }
106 
107     /**
108      * Create a Child Logger of this Logger.
109      */
110     protected Logger newLogger(String fullname)
111     {
112         return new Slf4jLog(fullname);
113     }
114 
115     public void ignore(Throwable ignored)
116     {
117         if (Log.isIgnored())
118         {
119             warn(Log.IGNORED, ignored);
120         }
121     }
122 
123     @Override
124     public String toString()
125     {
126         return _logger.toString();
127     }
128 }