View Javadoc

1   package org.astrogrid.tools.log;
2   
3   /***
4    * A covenience singleton, providing easy to use access to logging facilities,
5    * for example:
6    * <pre>
7    *     Log.logError("Could not do task xxx");
8    * or
9    *     Log.logError("Could not do task xxxx",exception);
10   * </pre>
11   * if you have an exception to log.
12   * <p>
13   * trace code can be logged as follows:
14   * <pre>
15   *     Log.trace("Starting xxx...");
16   * </pre>
17   * and turn it on/off by:
18   * <pre>
19   *     Log.traceOn();
20   * or
21   *     Log.traceOff();
22   * </pre>
23   * <p>
24   * Assertion-style checks can be made as follows:
25   * <pre>
26   *     Log.affirm(condition that should be true, "Message if it is not");
27   * </pre>
28   * ('assert' has become a keyword in JDK 1.4)
29   *
30   * NB; at the moment the implementation is using the net.mchill.log package
31   * which is not 'standard'.  At some point it needs to be converted over
32   * to log4j or JDKs 1.4 as necessary. (Or all three, then whichever is
33   * wanted can be included in the class path... hmmm...)
34   *
35   * @Created          : Oct 2002
36   * @author           : M Hill
37   */
38  
39  public class Log
40  {
41     public static boolean traceOn = true;
42  
43     /***
44      * A simple static method implementing an assertion check.  Renamed to
45      * affirm to avoid JDK 1.4s warnings about using assert.
46      */
47     public static void affirm(boolean assertion, String errorMessage)
48     {
49        //net.mchill.log.Log.affirm(assertion, errorMessage);
50     }
51  
52     /*** Convenience method for logging alarms */
53     public static void logAlarm( String message )
54     {
55        //net.mchill.log.Log.logEvent(new net.mchill.log.LogEvent(net.mchill.log.Severity.ALARM, message));
56     }
57  
58     /*** Convenience method for logging alarms */
59     public static void logAlarm(String userMessage, String detailMessage )
60     {
61        //net.mchill.log.Log.logEvent(new net.mchill.log.LogEvent(null, net.mchill.log.Severity.ALARM, userMessage, detailMessage, null));
62     }
63  
64     /*** Convenience method for logging warnings */
65     public static void logWarning( String message )
66     {
67        //net.mchill.log.Log.logEvent(new net.mchill.log.LogEvent(net.mchill.log.Severity.WARNING, message));
68     }
69  
70     /*** Convenience method for logging warnings */
71     public static void logWarning(Object aSource, String message, Throwable th )
72     {
73        //net.mchill.log.Log.logEvent(new net.mchill.log.LogEvent(aSource, net.mchill.log.Severity.WARNING, message, "", th));
74     }
75  
76     /*** Convenience method for logging warnings */
77     public static void logWarning(Object aSource, String message, String moreInfo )
78     {
79        //net.mchill.log.Log.logEvent(new net.mchill.log.LogEvent(aSource, net.mchill.log.Severity.WARNING, message, moreInfo, null));
80     }
81  
82     /*** Convenience method for logging warnings */
83     public static void logWarning(Object aSource, String message, String moreInfo, Throwable th )
84     {
85        //net.mchill.log.Log.logEvent(new net.mchill.log.LogEvent(aSource, net.mchill.log.Severity.WARNING, message, moreInfo, th));
86     }
87  
88     /*** Convenience method for logging info messages */
89     public static void logInfo( String message )
90     {
91        //net.mchill.log.Log.logEvent(new net.mchill.log.LogEvent(net.mchill.log.Severity.INFO, message));
92     }
93  
94     /*** Convenience method for logging info messages */
95     public static void logInfo(Object aSource, String message )
96     {
97        //net.mchill.log.Log.logEvent(new net.mchill.log.LogEvent(aSource, net.mchill.log.Severity.INFO, message, "", null));
98     }
99  
100    /*** Convenience method for logging info messages */
101    public static void logInfo(String message, String usefulInfo )
102    {
103       //net.mchill.log.Log.logEvent(new net.mchill.log.LogEvent(null, net.mchill.log.Severity.INFO, message, usefulInfo, null));
104    }
105 
106    /*** Convenience method for logging program errors */
107    public static void logError( String message )
108    {
109       //net.mchill.log.Log.logEvent(new net.mchill.log.LogEvent(net.mchill.log.Severity.ERROR, message));
110    }
111 
112    /*** Convenience method for logging program errors */
113    public static void logError( String message, Throwable th )
114    {
115       //net.mchill.log.Log.logEvent(new net.mchill.log.LogEvent(null,net.mchill.log.Severity.ERROR, message, "", th));
116    }
117 
118    /*** Convenience method for logging program errors */
119    public static void logError( String message, String moreInfo, Throwable th )
120    {
121       //net.mchill.log.Log.logEvent(new net.mchill.log.LogEvent(null,net.mchill.log.Severity.ERROR, message, moreInfo, th));
122    }
123 
124    /*** Convenience method for logging program errors */
125    public static void logError(Object trap, String message, Throwable th )
126    {
127       //net.mchill.log.Log.logEvent(new net.mchill.log.LogEvent(trap, net.mchill.log.Severity.ERROR, message, "", th));
128    }
129 
130    /*** Convenience method for logging program errors */
131    public static void logError(Object trap, String message, String moreInfo, Throwable th )
132    {
133       //net.mchill.log.Log.logEvent(new net.mchill.log.LogEvent(trap, net.mchill.log.Severity.ERROR, message, moreInfo, th));
134    }
135 
136    /*** Convenience method for logging program error messages that
137     * will be reported with some other severity (eg warning) */
138    public static void logError(String foo /*net.mchill.log.Severity severity*/, String message, String moreInfo, Throwable th )
139    {
140       //net.mchill.log.Log.logEvent(new net.mchill.log.LogEvent(null,severity, message, moreInfo, th));
141    }
142 
143    /*** Convenience method for logging assertion-style debugging info
144     * and trace output. */
145    public static void logDebug( String message )
146    {
147       logDebug(message, null);
148    }
149 
150    /*** Convenience method for logging assertion-style debugging info.
151     * For example, if a connection fails, the user will be notified
152     * but you might use this to add more detailed technical
153     * information.*/
154    public static void logDebug( String message, Throwable th )
155    {
156       //net.mchill.log.Log.logDebug(message, th);
157    }
158 
159    /*** Convenience method for adding trace code that can be distributed like
160     * other log messages. */
161    public static void trace( String message )
162    {
163       if (traceOn)
164       {
165          //net.mchill.log.Log.trace(message);
166       }
167    }
168 
169    /*** Switch trace on - ie allow trace messages to be logged */
170    public static void traceOn()     { traceOn = true; }
171 
172    /*** Switch trace off - ie stop trace messages from being logged */
173    public static void traceOff()    { traceOn = false; }
174 }