Project Report: fawkez

Packagesummary org.jcoderz.commons.tracing

org.jcoderz.commons.tracing.JulTracer

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 java.util.logging.Level;
36  import java.util.logging.Logger;
37  
38  /**
39   * A Tracer implementation that used {@link java.util.logging}
40   * entering exiting logger as tracing sink.
41   * See {@link Logger#entering(String, String)} for an example.
42   *
43   * @author Andreas Mandel
44   */
45 (1)public class JulTracer
46      implements Tracer
47  {
48      /** The backing java logger. */
49 (2)    private final Logger mLogger;
50      /** Name of the class where this logger belongs to. */
51      private final String mClassName;
52      
53      
54      /**
55       * Create a new instance of this Tracer.
56       * The underlying java logger is instantly created. 
57       * @param tracerName the name of the tracer to be created, should be
58       *     equal to the name of the class that uses the tracer.
59       */
60      private JulTracer (String tracerName)
610     {
620         mLogger = Logger.getLogger(tracerName);
630         mClassName = tracerName;
640     }
65  
66      /**
67       * Factory for a tracer for classes with the given name.
68       * @param className the name of the class that uses this tracer.
69       * @return a tracer for the given class that dumps trace output to
70       *      java logging.
71       */
72      public static JulTracer getTracer (String className)
73      {
740         return new JulTracer(className);
75      }
76  
77  
78      /**
79       * Returns true, if the level of the underlying java logger is
80       * {@link Level#FINER} or below.
81       * @see org.jcoderz.commons.tracing.Tracer#isTracing()
82       */
83 (3)    public boolean isTracing ()
84      {
850         return mLogger.isLoggable(Level.FINER);
86      }
87  
88      /**
89       * Returns always true.
90       * @see org.jcoderz.commons.tracing.Tracer#isTracingArguments()
91       */
92 (4)    public boolean isTracingArguments ()
93      {
940         return true;
95      }
96  
97      /**
98       * Returns the Name of the class where this tracer belongs to.
99       * @return the Name of the class where this tracer belongs to.
100       */
101      public String getClassName ()
102      {
1030         return mClassName;
104      }
105  
106      /**
107       * Delegates to {@link Logger#entering(String, String)}.
108       * The className is expected to be the same as the tracer name and 
109       * is silently ignored.
110       * @see Tracer#entering(java.lang.String, java.lang.String)
111       */
112 (5)(6)(7)    public TracingToken entering (String className, String methodName)
113      {
114          final TracingToken result;
1150         if (isTracing())
116          {
1170             mLogger.entering(getClassName(), methodName);
1180             result = new JulTracingToken(methodName);
119          }
120          else
121          {
1220             result = null;
123          }
1240         return result;
125      }
126  
127      /**
128       * Delegates to {@link Logger#entering(String, String, Object)}.
129       * The className is expected to be the same as the tracer name and 
130       * is silently ignored.
131       * @see Tracer#entering(String, String, Object)
132       */
133 (8)(9)(10)    public TracingToken entering (String className, String methodName,
134 (11)        Object argument)
135      {
136          final TracingToken result;
1370         if (isTracing())
138          {
1390             mLogger.entering(getClassName(), methodName, argument);
1400             result = new JulTracingToken(methodName);
141          }
142          else
143          {
1440             result = null;
145          }
1460         return result;
147      }
148  
149      /**
150       * Delegates to {@link Logger#entering(String, String, Object)}.
151       * The className is expected to be the same as the tracer name and 
152       * is silently ignored.
153       * @see Tracer#entering(String, String, Object[])
154       */
155 (12)(13)(14)    public TracingToken entering (String className, String methodName,
156 (15)        Object[] arguments)
157      {
158          final TracingToken result;
1590         if (isTracing())
160          {
1610             mLogger.entering(getClassName(), methodName, arguments);
1620             result = new JulTracingToken(methodName);
163          }
164          else
165          {
1660             result = null;
167          }
1680         return result;
169      }
170  
171      /**
172       * Delegates to {@link Logger#exiting(String, String)}.
173       * If the token is not a {@link JulTracingToken} the call is
174       * silently ignored.
175       * @see Tracer#exiting(TracingToken)
176       */
177 (16)(17)    public void exiting (TracingToken token)
178      {
1790         if (token instanceof JulTracingToken)
180          {
1810             final JulTracingToken julTracingToken = (JulTracingToken) token;
1820             mLogger.exiting(getClassName(), julTracingToken.getMethodName());
183          }
1840     }
185  
186      /**
187       * Delegates to {@link Logger#exiting(String, String)}.
188       * If the token is not a {@link JulTracingToken} the call is
189       * silently ignored.
190       * @see Tracer#exiting(TracingToken, java.lang.Object)
191       */
192 (18)(19)(20)    public void exiting (TracingToken token, Object result)
193      {
1940         if (token instanceof JulTracingToken)
195          {
1960             final JulTracingToken julTracingToken = (JulTracingToken) token;
1970             mLogger.exiting(
198                  getClassName(), julTracingToken.getMethodName(), result);
199          }
2000     }
201  
202      /**
203       * Delegates to {@link Logger#throwing(String, String, Throwable)}.
204       * If the token is not a {@link JulTracingToken} the call is
205       * silently ignored.
206       * @see Tracer#throwing(TracingToken, java.lang.Throwable)
207       */
208 (21)(22)(23)    public void throwing (TracingToken token, Throwable thrown)
209      {
2100         if (token instanceof JulTracingToken)
211          {
2120             final JulTracingToken julTracingToken = (JulTracingToken) token;
2130             mLogger.throwing(getClassName(), julTracingToken.getMethodName(),
214                  thrown);
215          }
2160     }
217      
218      /**
219       * Stores context information for the {@link JulTracer}.
220       * @see TracingToken
221       * @author Andreas Mandel
222       */
223      private class JulTracingToken implements TracingToken
224      {
225          private final String mMethodName;
226          
227          public JulTracingToken (String methodName)
2280(24)        {
2290             mMethodName = methodName;
2300         }
231  
232          public String getMethodName ()
233          {
2340             return mMethodName;
235          }
236          
237      }
238  }

Findings in this File

c (1) 45 : 0 Class JulTracer should be declared as final.
d (2) 49 : 26 The Logger variable declaration does not contain the static and final modifiers
c (3) 83 : 0 Expected an @return tag.
c (4) 92 : 0 Expected an @return tag.
c (5) 112 : 0 Expected an @return tag.
c (6) 112 : 42 Expected @param tag for 'className'.
c (7) 112 : 60 Expected @param tag for 'methodName'.
c (8) 133 : 0 Expected an @return tag.
c (9) 133 : 42 Expected @param tag for 'className'.
c (10) 133 : 60 Expected @param tag for 'methodName'.
c (11) 134 : 16 Expected @param tag for 'argument'.
c (12) 155 : 0 Expected an @return tag.
c (13) 155 : 42 Expected @param tag for 'className'.
c (14) 155 : 60 Expected @param tag for 'methodName'.
c (15) 156 : 18 Expected @param tag for 'arguments'.
c (16) 177 : 39 Expected @param tag for 'token'.
d (17) 177 : 0 Tag @link: reference not found: JulTracingToken
c (18) 192 : 39 Expected @param tag for 'token'.
c (19) 192 : 53 Expected @param tag for 'result'.
d (20) 192 : 0 Tag @link: reference not found: JulTracingToken
c (21) 208 : 40 Expected @param tag for 'token'.
c (22) 208 : 57 Expected @param tag for 'thrown'.
d (23) 208 : 0 Tag @link: reference not found: JulTracingToken
w (24) 228 : 0 Should org.jcoderz.commons.tracing.JulTracer$JulTracingToken be a _static_ inner class?