View Javadoc

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