Project Report: fawkez

Packagesummary org.jcoderz.commons.tracing

org.jcoderz.commons.tracing.Slf4jTracer

LineHitsNoteSource
1  /*
2   * $Id: ArraysUtil.java 1011 2008-06-16 17:57:36Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.commons.tracing;
34  
35  import org.slf4j.Logger;
36  import org.slf4j.LoggerFactory;
37  
38  
39  /**
40   * A Tracer implementation that used {@link org.slf4j.Logger}
41   * as tracing sink.
42   * See {@link java.util.logging.Logger#entering(String, String)} for an
43   * example of the format and semantic used.
44   * 
45 (1) * TODO: Need Marker for classname & methodname? How?
46   *
47   * @author Andreas Mandel
48   */
49 (2)public class Slf4jTracer
50      implements Tracer
51  {
52      /** The backing java logger. */
53 (3)    private final Logger mLogger;
54      /** Name of the class where this logger belongs to. */
55      private final String mClassName;
56      
57      
58      /**
59       * Create a new instance of this Tracer.
60       * The underlying java logger is instantly created. 
61       * @param tracerName the name of the tracer to be created, should be
62       *     equal to the name of the class that uses the tracer.
63       */
64      private Slf4jTracer (String tracerName)
650     {
660         mLogger = LoggerFactory.getLogger(tracerName);
670         mClassName = tracerName;
680     }
69  
70      /**
71       * Factory for a tracer for classes with the given name.
72       * @param className the name of the class that uses this tracer.
73       * @return a tracer for the given class that dumps trace output to
74       *      java logging.
75       */
76      public static Slf4jTracer getTracer (String className)
77      {
780         return new Slf4jTracer(className);
79      }
80  
81  
82      /**
83       * Returns true, if the level of the underlying slf4j logger has
84       * trace enabled.
85       * @see Logger#isTraceEnabled()
86       */
87 (4)    public boolean isTracing ()
88      {
890         return mLogger.isTraceEnabled();
90      }
91  
92      /**
93       * Returns always true.
94       * @see org.jcoderz.commons.tracing.Tracer#isTracingArguments()
95       */
96 (5)    public boolean isTracingArguments ()
97      {
980         return true;
99      }
100  
101      /**
102       * Returns the Name of the class where this tracer belongs to.
103       * @return the Name of the class where this tracer belongs to.
104       */
105      public String getClassName ()
106      {
1070         return mClassName;
108      }
109  
110      /**
111       * Delegates to {@link Logger#trace(org.slf4j.Marker, String).
112       * The className is expected to be the same as the tracer name and 
113       * is silently ignored.
114       * @see Tracer#entering(java.lang.String, java.lang.String)
115       */
116 (6)(7)(8)(9)    public TracingToken entering (String className, String methodName)
117      {
118          final TracingToken result;
1190         if (isTracing())
120          {
1210             mLogger.trace(/* getClassName(), methodName, */ "ENTRY");
1220             result = new Slf4jTracingToken(methodName);
123          }
124          else
125          {
1260             result = null;
127          }
1280         return result;
129      }
130  
131      /**
132       * Delegates to {@link Logger#trace(String, Object)}.
133       * The className is expected to be the same as the tracer name and 
134       * is silently ignored.
135       * @see Tracer#entering(String, String, Object)
136       */
137 (10)(11)(12)    public TracingToken entering (String className, String methodName,
138 (13)        Object argument)
139      {
140          final TracingToken result;
1410         if (isTracing())
142          {
1430             mLogger.debug(/* getClassName(), methodName, */ "ENTRY {}",
144                  argument);
1450             result = new Slf4jTracingToken(methodName);
146          }
147          else
148          {
1490             result = null;
150          }
1510         return result;
152      }
153  
154      /**
155       * Delegates to {@link Logger#trace(String, String, Object)}.
156       * The className is expected to be the same as the tracer name and 
157       * is silently ignored.
158       * @see Tracer#entering(String, String, Object[])
159       */
160 (14)(15)    public TracingToken entering (
161 (16)(17)(18)        String className, String methodName, Object[] arguments)
162      {
163          final TracingToken result;
1640         if (isTracing())
165          {
1660             String msg = "ENTRY";
1670(19)            if (arguments == null )
168              {
1690                result = entering(className, methodName);
170              }
171              else
172              {
1730                 for (int i = 0; i < arguments.length; i++)
174                  {
1750(20)(21)                    msg = msg + " {}";
176                  }
1770                 mLogger.trace(/*getClassName(), methodName,*/ msg, arguments);
1780                 result = new Slf4jTracingToken(methodName);
179              }
1800         }
181          else
182          {
1830             result = null;
184          }
1850         return result;
186      }
187  
188      /**
189       * Delegates to {@link Logger#trace(String, Object)} the message
190       * string used is "RETURN".
191       * If the token is not a {@link Slf4jTracingToken} the call is
192       * silently ignored.
193       * @see Tracer#exiting(TracingToken)
194       */
195 (22)(23)    public void exiting (TracingToken token)
196      {
1970         if (token instanceof Slf4jTracingToken)
198          {
199              // final Slf4jTracingToken tt = (Slf4jTracingToken) token;
2000             mLogger.trace(/* getClassName(), tt.getMethodName(), */ "RETURN");
201          }
2020     }
203  
204      /**
205       * Delegates to {@link Logger#trace(String, Object)}.
206       * If the token is not a {@link Slf4jTracingToken} the call is
207       * silently ignored.
208       * @see Tracer#exiting(TracingToken, java.lang.Object)
209       */
210 (24)(25)(26)    public void exiting (TracingToken token, Object result)
211      {
2120         if (token instanceof Slf4jTracingToken)
213          {
214              // final Slf4jTracingToken tt = (Slf4jTracingToken) token;
2150             mLogger.trace(
216                  /* getClassName(), tt.getMethodName(), */ "RETURN {}",
217                  result);
218          }
2190     }
220  
221      /**
222       * Delegates to {@link Logger#throwing(String, String, Throwable)}.
223       * If the token is not a {@link Slf4jTracingToken} the call is
224       * silently ignored.
225       * @see Tracer#throwing(TracingToken, java.lang.Throwable)
226       */
227 (27)(28)(29)(30)    public void throwing (TracingToken token, Throwable thrown)
228      {
2290         if (token instanceof Slf4jTracingToken)
230          {
231              // final Slf4jTracingToken tt = (Slf4jTracingToken) token;
2320             mLogger.trace(
233                  /* getClassName(), tt.getMethodName(), */ "THROW",
234                  thrown);
235          }
2360     }
237      
238      /**
239       * Stores context information for the {@link Slf4jTracer}.
240       * @see TracingToken
241       * @author Andreas Mandel
242       */
243      private class Slf4jTracingToken implements TracingToken
244      {
245          private final String mMethodName;
246          
247          public Slf4jTracingToken (String methodName)
2480(31)        {
2490             mMethodName = methodName;
2500         }
251  
252          public String getMethodName ()
253          {
2540             return mMethodName;
255          }
256          
257      }
258  }

Findings in this File

i (1) 45 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'.
c (2) 49 : 0 Class Slf4jTracer should be declared as final.
d (3) 53 : 26 The Logger variable declaration does not contain the static and final modifiers
c (4) 87 : 0 Expected an @return tag.
c (5) 96 : 0 Expected an @return tag.
c (6) 116 : 0 Expected an @return tag.
c (7) 116 : 42 Expected @param tag for 'className'.
c (8) 116 : 60 Expected @param tag for 'methodName'.
c (9) 116 : 0 Missing closing '}' character for inline tag: "{@link Logger#trace(org.slf4j.Marker, String).
c (10) 137 : 0 Expected an @return tag.
c (11) 137 : 42 Expected @param tag for 'className'.
c (12) 137 : 60 Expected @param tag for 'methodName'.
c (13) 138 : 16 Expected @param tag for 'argument'.
c (14) 160 : 0 Expected an @return tag.
d (15) 160 : 0 Tag @link: can't find trace(String, String, Object) in org.slf4j.Logger
c (16) 161 : 16 Expected @param tag for 'className'.
c (17) 161 : 34 Expected @param tag for 'methodName'.
c (18) 161 : 55 Expected @param tag for 'arguments'.
c (19) 167 : 34 ')' is preceded with whitespace.
w (20) 175 : 0 Method org.jcoderz.commons.tracing.Slf4jTracer.entering(String, String, Object[]) concatenates strings using + in a loop
c (21) 175 : 21 Prefer StringBuffer over += for concatenating strings
c (22) 195 : 39 Expected @param tag for 'token'.
d (23) 195 : 0 Tag @link: reference not found: Slf4jTracingToken
c (24) 210 : 39 Expected @param tag for 'token'.
c (25) 210 : 53 Expected @param tag for 'result'.
d (26) 210 : 0 Tag @link: reference not found: Slf4jTracingToken
c (27) 227 : 40 Expected @param tag for 'token'.
c (28) 227 : 57 Expected @param tag for 'thrown'.
d (29) 227 : 0 Tag @link: can't find throwing(String, String, Throwable) in org.slf4j.Logger
d (30) 227 : 0 Tag @link: reference not found: Slf4jTracingToken
w (31) 248 : 0 Should org.jcoderz.commons.tracing.Slf4jTracer$Slf4jTracingToken be a _static_ inner class?