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 implements Logger
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  
31      public Slf4jLog(String name)
32      {
33          // This checks to make sure that an slf4j implementation is present.
34          // It is needed because slf4j-api 1.6.x defaults to using NOPLogger.
35          try
36          {
37              Class.forName("org.slf4j.impl.StaticLoggerBinder");
38          }
39          catch (ClassNotFoundException ex)
40          {
41              throw new NoClassDefFoundError("org.slf4j.impl.StaticLoggerBinder");
42          }
43  
44          org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger( name );
45          // Fix LocationAwareLogger use to indicate FQCN of this class - 
46          // https://bugs.eclipse.org/bugs/show_bug.cgi?id=276670
47          if (logger instanceof org.slf4j.spi.LocationAwareLogger)
48          {
49              _logger = new JettyAwareLogger((org.slf4j.spi.LocationAwareLogger)logger);
50          }
51          else
52          {
53              _logger = logger;
54          }
55      }
56  
57      public String getName()
58      {
59          return _logger.getName();
60      }
61  
62      public void warn(String msg, Object... args)
63      {
64          _logger.warn(msg, args);
65      }
66  
67      public void warn(Throwable thrown)
68      {
69          warn("", thrown);
70      }
71  
72      public void warn(String msg, Throwable thrown)
73      {
74          _logger.warn(msg, thrown);
75      }
76  
77      public void info(String msg, Object... args)
78      {
79          _logger.info(msg, args);
80      }
81  
82      public void info(Throwable thrown)
83      {
84          info("", thrown);
85      }
86  
87      public void info(String msg, Throwable thrown)
88      {
89          _logger.info(msg, thrown);
90      }
91  
92      public void debug(String msg, Object... args)
93      {
94          _logger.debug(msg, args);
95      }
96  
97      public void debug(Throwable thrown)
98      {
99          debug("", thrown);
100     }
101 
102     public void debug(String msg, Throwable thrown)
103     {
104         _logger.debug(msg, thrown);
105     }
106 
107     public boolean isDebugEnabled()
108     {
109         return _logger.isDebugEnabled();
110     }
111 
112     public void setDebugEnabled(boolean enabled)
113     {
114         warn("setDebugEnabled not implemented",null,null);
115     }
116 
117     public Logger getLogger(String name)
118     {
119         return new Slf4jLog(name);
120     }
121 
122     public void ignore(Throwable ignored)
123     {
124         if (Log.isIgnored())
125         {
126             warn(Log.IGNORED, ignored);
127         }
128     }
129 
130     @Override
131     public String toString()
132     {
133         return _logger.toString();
134     }
135 }