KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > protomatter > syslog > Syslog


1 package com.protomatter.syslog;
2
3 /**
4  * {{{ The Protomatter Software License, Version 1.0
5  * derived from The Apache Software License, Version 1.1
6  *
7  * Copyright (c) 1998-2002 Nate Sammons. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution,
22  * if any, must include the following acknowledgment:
23  * "This product includes software developed for the
24  * Protomatter Software Project
25  * (http://protomatter.sourceforge.net/)."
26  * Alternately, this acknowledgment may appear in the software itself,
27  * if and wherever such third-party acknowledgments normally appear.
28  *
29  * 4. The names "Protomatter" and "Protomatter Software Project" must
30  * not be used to endorse or promote products derived from this
31  * software without prior written permission. For written
32  * permission, please contact support@protomatter.com.
33  *
34  * 5. Products derived from this software may not be called "Protomatter",
35  * nor may "Protomatter" appear in their name, without prior written
36  * permission of the Protomatter Software Project
37  * (support@protomatter.com).
38  *
39  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
40  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
41  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42  * DISCLAIMED. IN NO EVENT SHALL THE PROTOMATTER SOFTWARE PROJECT OR
43  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
46  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
47  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
49  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE. }}}
51  */

52
53 import java.io.*;
54 import java.net.*;
55 import java.util.*;
56 import java.lang.reflect.*;
57 import java.text.MessageFormat JavaDoc;
58 import com.protomatter.util.*;
59 import com.protomatter.Protomatter;
60
61 /**
62  * This class implements a system-wide logging utility. Please read the <a
63  * HREF="syslog-whitepaper.html">Syslog Whitepaper</a> for more information. It
64  * allows a program to log messages and objects at different severity levels in
65  * a standardized way. The implementation of the log is specified by an object
66  * which implements the Syslogger interface. You can have multiple log
67  * implementations, and each can have it's own log mask or can inherit it's log
68  * mask from Syslog (this is the default behavior).<P>
69  *
70  * There are 5 severity levels: DEBUG, INFO, WARNING, ERROR, FATAL. They
71  * correspond to the numbers 0, 4, 8, 12, and 16, respectively. You can enable
72  * logging for any combination of these levels. The default setting logs only
73  * WARNING and above.<P>
74  *
75  *
76  * <DL>
77  * <DT> <B>Quickie introduction and usage:</B> </DT>
78  * <DD>
79  * <TABLEBORDER=1 CELLPADDING=5 CELLSPACING=0>
80  *
81  * <TR>
82  *
83  * <TD>
84  * Anywhere you're doing this: <BLOCKQUOTE> <TT>
85  * System.out.println("Some message");</TT> </BLOCKQUOTE> <P>
86  *
87  * Do this instead: <BLOCKQUOTE> <TT>Syslog.debug(this, "Some
88  * message");</TT> </BLOCKQUOTE> <P>
89  *
90  * If you're in a <tt>static</tt> method, do this: <BLOCKQUOTE> <TT>
91  * Syslog.debug(MyClass.class, "Some message");</TT> </BLOCKQUOTE> <P>
92  *
93  * If you like what this gets you, start playing around with different
94  * log levels (call "<TT>Syslog.info(...)</TT> " and others). If you
95  * like that, start playing around with channels and configuring the
96  * loggers and other things. Syslog has a <u>very</u> robust API and
97  * can be bent around to do all sorts of things, but it <u>does not
98  * have to be complicated to use</u> even though it <u>can</u> be
99  * configured in all sorts of complicated ways.
100  * </TD>
101  *
102  * </TR>
103  *
104  * </TABLE>
105  * </DD>
106  * </DL>
107  * <P>
108  *
109  *
110  * <DL>
111  * <DT> <B>More involved usage examples:</B> </DT>
112  * <DD>
113  * <TABLEBORDER=1 CELLPADDING=5 CELLSPACING=0>
114  *
115  * <TR>
116  * <TD>
117  * <pre>
118  * // log simple message at DEBUG level
119  * // pass 'this' as the object performing the logging
120  * Syslog.log(this, "simple message", null, Syslog.DEBUG);<P>
121  *
122  * // this performs toString() on object 'obj', and prints a message
123  * Syslog.log(this, "logging object", obj, Syslog.INFO);<P>
124  *
125  * // logs 'exception' and its stack trace at ERROR level
126  * Syslog.log(this, exception);<P>
127  *
128  * // here's how you log in a static method -- pass the class object
129  * Syslog.log(MyClass.class, "logging in MyClass");<P>
130  *
131  * // shortcuts for each log level Syslog.debug(this, "foo");
132  * Syslog.debug(this, "foo", bar); Syslog.info(this, "foo");
133  * Syslog.info(this, "foo", bar);<P>
134  *
135  * // log to multiple channels (the "foo" and "bar" channels)
136  * Syslog.infoToChannel(this, new String[]{"foo", "bar"}, "My
137  * message"); </pre>
138  * </TD>
139  * </TR>
140  * </TABLE>
141  * </DD>
142  * </DL>
143  * <P>
144  *
145  * There are basically three types of methods on this class for issuing log
146  * messages. Whenever a channel name is not specified, the channel <tt>
147  * DEFAULT_CHANNEL</tt> is used.<P>
148  *
149  * Whenever a channel is specified, it is an <tt>Object</tt> . This argument
150  * can either be a <tt>String</tt> or an array of <tt>String</tt> (in which
151  * case, the message will be sent out to multiple channels).<P>
152  *
153  *
154  * <ul>
155  * <dl>
156  * <dt> <tt>log(...);</tt> <br>
157  * </dt>
158  * <dd> They have the following forms:<P>
159  *
160  * </dd>
161  * <dd> <tt> log(Object logger, Throwable t);<br>
162  * log(Object logger, Throwable t, int level);<br>
163  * log(Object logger, Object msg, Object detail, int level);<br>
164  * log(Object logger, Object chan, Object msg, Object detail, int level);
165  * <br>
166  * log(InetAddress host, Object logger, Throwable t);<br>
167  * log(InetAddress host, Object logger, Throwable t, int level);<br>
168  * log(InetAddress host, Object logger, Object msg, Object detail, int
169  * level);<br>
170  * log(InetAddress host, Object logger, Object chan, Object msg, Object
171  * detail, int level);<br>
172  * </tt> </dd> <P>
173  *
174  *
175  * <dt> <tt>xxx(...);</tt> <br>
176  * </dt>
177  * <dd> Where "<tt>xxx</tt> " is "<tt>debug</tt> ", "<tt>info</tt> ", "<tt>
178  * warning</tt> ", "<tt>error</tt> ", or "<tt>fatal</tt> " These are
179  * shortcuts to the <tt>log(...)</tt> method for each log level. They have
180  * the following forms:<P>
181  *
182  * </dd>
183  * <dd> <tt> xxx(Object logger, Object msg);<br>
184  * xxx(Object logger, Object msg, Object detail);<br>
185  * xxx(InetAddress host, Object logger, Object msg);<br>
186  * xxx(InetAddress host, Object logger, Object msg, Object detail);<br>
187  * </tt> </dd> <P>
188  *
189  *
190  * <dt> <tt>xxxToChannel(...);</tt> <br>
191  * </dt>
192  * <dd> Where "<tt>xxx</tt> " is "<tt>debug</tt> ", "<tt>info</tt> ", "<tt>
193  * warning</tt> ", "<tt>error</tt> ", or "<tt>fatal</tt> " These are
194  * shortcuts to the <tt>log(...)</tt> method for each log level, and to a
195  * specific channel. They have the following forms:<P>
196  *
197  * </dd>
198  * <dd> <tt> xxxToChannel(Object logger, Object chan, Object msg);<br>
199  * xxxToChannel(Object logger, Object chan, Object msg, Object detail);<br>
200  * xxxToChannel(InetAddress host, Object logger, Object chan, Object msg);
201  * <br>
202  * xxxToChannel(InetAddress host, Object logger, Object chan, Object msg,
203  * Object detail);<br>
204  * </tt> </dd> <P>
205  *
206  *
207  * </dl>
208  *
209  * </ul><P>
210  *
211  * You may want to look at the <tt><a HREF="Channel.html">Channel</a></tt>
212  * class. Some people prefet its API.<P>
213  *
214  * When the <TT>Syslog</TT> class is loaded, the following happens:<P>
215  *
216  *
217  * <ol>
218  * <li> If the <tt>Syslog.level</tt> system property is set, it is passed to
219  * <tt>Syslog.setLogMask(...)</tt> (otherwise it defaults to <tt>WARNING</tt>
220  * ).<P>
221  *
222  *
223  * <li> A <tt>PrintWriterLog</tt> named "<TT>PrintWriterLog.err</TT> " is
224  * added using <tt>Syslog.addLogger(...)</tt> and connected to the <tt>
225  * System.err</tt> PrintStream.<P>
226  *
227  *
228  * <li> If the <tt>Syslog.file</tt> system property is set, it is interpreted
229  * as a filename and another <tt>PrintWriterLog</tt> is added and connected
230  * to that file. The logger is named "<TT>PrintWriterLog.file</TT> ".
231  * </ol>
232  * <P>
233  *
234  * If you want to change these defaults, you can use the <tt>getLoggers()</tt>
235  * , <tt>addLogger(...)</tt> , <tt>removeLogger(...)</tt> and <tt>
236  * removeAllLoggers()</tt> methods to change what loggers are registered with
237  * <tt>Syslog</tt> .<P>
238  *
239  * Syslog provides background work queues for loggers that need to perform
240  * their operations asynchronously. For instance, the <tt>MailLog</tt> performs
241  * its policy check synchronously and then if it decides that a message will
242  * actually need to be sent, it asks syslog to perform the operation
243  * asynchronously. This is far more efficient than doing <i>everything</i> in
244  * the background because the amount of synchronization necessary to add work
245  * to a queue is usually larger than a policy check.<P>
246  *
247  * <B>Please read the <a HREF="syslog-whitepaper.html">Syslog Whitepaper</a>
248  * for more information on Syslog.</B> <P>
249  *
250  *
251  *
252  *@author nate
253  *@created May 3, 2002
254  *@see Syslogger
255  *@see SyslogChannelAware
256  */

257 public class Syslog
258 {
259     public static final Debug debugging = Debug.forPackage(Syslog.class);
260
261     /**
262      * A log generated during debugging of the software.
263      */

264     public final static int DEBUG = 1;
265
266     /**
267      * An informational message that might come in handy later.
268      */

269     public final static int INFO = 2;
270
271     /**
272      * A warning message that the system administrator might want to know
273      * about.
274      */

275     public final static int WARNING = 4;
276
277     /**
278      * One of the software components caused an error or exception.
279      */

280     public final static int ERROR = 8;
281
282     /**
283      * One of the software components is no longer functional.
284      */

285     public final static int FATAL = 16;
286
287     /**
288      * Loggers can inherit Syslog's log mask by setting their log mask to this
289      * value.
290      */

291     public final static int INHERIT_MASK = 0;
292
293     /**
294      * The name of the default log channel.
295      */

296     public final static String JavaDoc DEFAULT_CHANNEL = "DEFAULT_CHANNEL";
297
298     /**
299      * The symbolic name for all channels.
300      */

301     public final static String JavaDoc ALL_CHANNEL = "*";
302
303     /**
304      * The current system-wide log mask. This variable is exposed so that
305      * policies that inherit their mask from Syslog can get the value faster
306      * than by calling a method.
307      */

308     public static int currentLogMask = atOrAbove(WARNING);
309
310     /**
311      * The name of a log channel for syslog configuration and system related
312      * messages.
313      */

314     public static String JavaDoc SYSLOG_CHANNEL_NAME = "SYSLOG";
315
316     /**
317      * A log channel for syslog configuration and system related messages.
318      */

319     public static Channel channel = Channel.getChannel(SYSLOG_CHANNEL_NAME);
320
321     // these loggers may or may not be synchronous.
322
private static List loggers;
323     private static Syslogger loggerArray[];
324
325     private static Syslog instance = null;
326
327     private static Map queueMap = new HashMap();
328
329     private static InetAddress localHost = null;
330
331     private static SyslogFlushThread flushThread = null;
332
333     // turns off everything.
334
private static boolean masterSwitch = true;
335
336     private static String JavaDoc[] defaultChannelList = new String JavaDoc[]{DEFAULT_CHANNEL};
337
338     private static String JavaDoc Q_MARK = "?";
339
340     private static ResourceBundle resources = null;
341
342     private static boolean computeCaller = false;
343
344     private static boolean alwaysComputeCaller = false;
345
346     /**
347      * Syslog classloader warning system property name.
348      */

349     public final static String JavaDoc WARNING_PROPERTY = "Syslog.classloader.warning";
350
351
352     /**
353      * Protected constructor. Please don't make a subclass of <TT>Syslog</TT>
354      * unless you really know what you're doing.
355      */

356     protected Syslog()
357     {
358         super();
359     }
360
361
362     /**
363      * Returns the global Syslog instance. You really should not need to get
364      * ahold of it, as all the methods are static. You might want to get it so
365      * that you can keep an instance around to keep the class from being
366      * unloaded if you're writing application servers.
367      *
368      *@return The instance value
369      */

370     public static Syslog getInstance()
371     {
372         return instance;
373     }
374
375     /**
376      * Set the flag for computing calling class and method
377      * names at runtime. Default is <tt>false</tt>.
378      */

379     public static void setComputeCaller(boolean setting)
380     {
381         computeCaller = setting;
382     }
383
384     /**
385      * Get the flag for computing calling class and method
386      * names at runtime. Default is <tt>false</tt>.
387      */

388     public static boolean getComputeCaller()
389     {
390         return computeCaller;
391     }
392
393
394     /**
395      * Set the flag for always computing calling class and method
396      * names at runtime. Default is <tt>false</tt>.
397      */

398     public static void setAlwaysComputeCaller(boolean setting)
399     {
400         alwaysComputeCaller = setting;
401     }
402
403     /**
404      * Get the flag for always computing calling class and method
405      * names at runtime. Default is <tt>false</tt>. If this is
406      * set to <tt>true</tt> then the correct method name and caller
407      * are always computed so they are available to the
408      * log policies. This can be overly expensive if you have
409      * lots of debug statements. If this flag is set to <tt>false</tt>
410      * then the caller class and method are only computed if
411      * the log call passes the policy check, and if the
412      * <tt>getComputeCallingClassAndMethod()</tt> flag is also
413      * set to <tt>true</tt>.
414      */

415     public static boolean getAlwaysComputeCaller()
416     {
417         return alwaysComputeCaller;
418     }
419
420
421     /**
422      * Get a map of the background work queues. The key to the map is the name
423      * of the queue, and the value is a <tt>{@link
424      * com.protomatter.util.WorkQueue com.protomatter.util.WorkQueue}</tt>
425      * object. You should <i>never</i> play with the queues -- this method is
426      * provided so that external processes can monitor the size of each queue
427      * by calling the <tt>getObjectPoolSize()</tt> method on each queue. The
428      * map itself is read-only.
429      *
430      *@return The workQueueMap value
431      */

432     public static Map getWorkQueueMap()
433     {
434         return Collections.unmodifiableMap(queueMap);
435     }
436
437
438     /**
439      * Static initializer. Performs the initialization steps described above
440      * when the class is loaded.
441      */

442     static
443     {
444         checkClassLoader();
445         instance = new Syslog();
446         loggers = new ArrayList();
447         loggerArray = new Syslogger[0];
448         init();
449     }
450
451
452     /**
453      * Check to see if we are being loaded by the system classloader or not.
454      */

455     private static void checkClassLoader()
456     {
457         ClassLoader JavaDoc loader = Syslog.class.getClassLoader();
458         String JavaDoc loaderString = loader.toString();
459         ClassLoader JavaDoc systemLoader = ClassLoader.getSystemClassLoader();
460         ClassLoader JavaDoc systemLoaderParent = systemLoader.getParent();
461         boolean warningFlag = "off".equalsIgnoreCase(System.getProperty(WARNING_PROPERTY));
462
463         if ((systemLoader != loader) && (systemLoaderParent != loader) && (!warningFlag))
464         {
465             System.err.println(" /***************************************************************************\\");
466             System.err.println(" * *");
467             System.err.println(" * Protomatter Syslog Classloader Warning *");
468             System.err.println(" * -------------------------------------- *");
469             System.err.println(" * *");
470             System.err.println(" * Protomatter Syslog has been loaded by a classloader other than *");
471             System.err.println(" * the system classloader. This indicates that the Syslog libraries *");
472             System.err.println(" * are not in the system CLASSPATH. Usually this is because Syslog *");
473             System.err.println(" * is being used in an application server and the Syslog libraries *");
474             System.err.println(" * are in the \"lib\" directory for a WebApp or EAR, etc. *");
475             System.err.println(" * *");
476             System.err.println(" * ClassLoader: " + StringUtil.pad(loaderString, 56) + " *");
477             System.err.println(" * *");
478             System.err.println(" * Syslog may not work as you might expect if it is not loaded by *");
479             System.err.println(" * the system classloader. Under some circumstances, users may want *");
480             System.err.println(" * to take advantage of features of this kind of configuration. If *");
481             System.err.println(" * this is the case, you can disable this warning message by setting *");
482             System.err.println(" * the \"Syslog.classloader.warning\" system property to \"off\". In *");
483             System.err.println(" * most cases, though, you don't want to do that. *");
484             System.err.println(" * *");
485             System.err.println(" * For more information on this behavior and the logic behind it, *");
486             System.err.println(" * please see the documentation at the following address: *");
487             System.err.println(" * *");
488             System.err.println(" * http://protomatter.sourceforge.net/" +
489                     StringUtil.pad(Protomatter.VERSION + "/javadoc/", 32) + " *");
490             System.err.println(" * com/protomatter/syslog/classloader-warning.html *");
491             System.err.println(" * *");
492             System.err.println(" \\**************************************************************************/");
493         }
494     }
495
496
497     /**
498      * Get the local hostname.
499      *
500      *@return The localHostName value
501      */

502     public static InetAddress getLocalHostName()
503     {
504         return localHost;
505     }
506
507
508     /**
509      * Set the number of milliseconds a flush thread should wait before
510      * flushing output on each logger. If the interval is 0 (or negative) the
511      * thread will be stopped. The default is not to have a flush thread
512      * running. You cannot set it to less than 1000ms, except for setting it to
513      * 0.
514      *
515      *@param interval The new flushThreadInterval value
516      */

517     public static void setFlushThreadInterval(long interval)
518     {
519         synchronized (instance)
520         {
521             if (flushThread != null)
522             {
523                 flushThread.stopRunning();
524                 flushThread = null;
525             }
526
527             if (interval > 0)
528             {
529                 if (interval < 1000)
530                 {
531                     throw new IllegalArgumentException JavaDoc(
532                             MessageFormat.format(getResourceString(MessageConstants.CANNOT_SET_FLUSH_INTERVAL_MESSAGE),
533                             new Object JavaDoc[]{"1000", "0"}));
534                 }
535
536                 flushThread = new SyslogFlushThread(interval);
537                 flushThread.start();
538             }
539         }
540     }
541
542
543     /**
544      * Get the sleep interval of the logger flush thread. This method will
545      * either return the number of milliseconds between flush calls, or zero if
546      * there is no flush thread running.
547      *
548      *@return The flushThreadInterval value
549      */

550     public static long getFlushThreadInterval()
551     {
552         synchronized (instance)
553         {
554             if (flushThread != null)
555             {
556                 return flushThread.getSleepInterval();
557             }
558             return 0;
559         }
560     }
561
562
563     /**
564      * Set the local hostname automatically. This sets the hostname to whatever
565      * <tt>InetAddress.getLocalHost()</tt> returns. This is called by <tt>
566      * SimpleSyslogTextFormatter</tt> when it is configured if it is supposed
567      * to log the host name.
568      */

569     public static void setLocalHostName()
570     {
571         try
572         {
573             setLocalHostName(InetAddress.getLocalHost());
574         }
575         catch (UnknownHostException x)
576         {
577             throw new IllegalStateException JavaDoc(getResourceString(MessageConstants.CANNOT_DETERMINE_HOSTNAME_MESSAGE));
578         }
579     }
580
581
582     /**
583      * Set the local hostname.
584      *
585      *@param host The new localHostName value
586      */

587     public static void setLocalHostName(InetAddress host)
588     {
589         localHost = host;
590     }
591
592
593     /**
594      * Set the value of the master switch. If this switch is set to <TT>false
595      * </TT>, then all log requests will be ignored.
596      *
597      *@param value The new masterSwitch value
598      */

599     public static void setMasterSwitch(boolean value)
600     {
601         masterSwitch = value;
602     }
603
604
605     /**
606      * Add work to the given background queue. Queues are created (but not
607      * destroyed) dynamically.
608      *
609      *@param queueName The feature to be added to the Work attribute
610      *@param r The feature to be added to the Work attribute
611      */

612     public static void addWork(String JavaDoc queueName, Runnable JavaDoc r)
613     {
614         WorkQueue queue = (WorkQueue)queueMap.get(queueName);
615         if (queue == null)
616         {
617             synchronized (queueMap)
618             {
619                 // re-check once in here to avoid race conditions.
620
queue = (WorkQueue)queueMap.get(queueName);
621                 if (queue == null)
622                 {
623                     queue = new WorkQueue("Syslog: " + queueName, 1);
624                     queueMap.put(queueName, queue);
625                 }
626             }
627         }
628         queue.addWork(r);
629     }
630
631
632     /**
633      * Initializes the logging facility. This gets called upon initialization,
634      * and can be called multiple times during a program. It checks the system
635      * properties file for "syslog.level" property and sets the default log
636      * mask to that value. Also, if "syslog.file" is defined, will log to that
637      * file.<P>
638      *
639      * If the "<tt>Syslog.config.xml</tt>" system property is set,
640      * then the XML configuration helper is loaded and Syslog
641      * is configured. See the <tt><a HREF="xml/SyslogXML.html#configure(org.jdom.Element)">SylogXML</a></tt>
642      * class for more information.
643      */

644     private final static synchronized void init()
645     {
646         resources = ResourceBundle.getBundle("com.protomatter.syslog.Syslog");
647
648         String JavaDoc loglevelstr = System.getProperty("Syslog.level");
649         if (loglevelstr != null)
650         {
651             // either give the value as the number or "DEBUG", etc...
652
try
653             {
654                 int loglevel = Integer.parseInt(loglevelstr);
655                 setLogMask(atOrAbove(loglevel));
656             }
657             catch (NumberFormatException JavaDoc x)
658             {
659                 setLogMask(loglevelstr);
660             }
661         }
662
663         // add the logger that writes to Stderr.
664
Syslogger l = new PrintWriterLog("System.err");
665         l.setName("PrintWriterLog.err");
666         addLogger(l);
667
668         // add a logger that writes to a file.
669
String JavaDoc logfilestr = System.getProperty("Syslog.file");
670         if (logfilestr != null)
671         {
672             FileLog fileLogger = new FileLog(new File(logfilestr));
673             fileLogger.setName("FileLog.file");
674             addLogger(fileLogger);
675         }
676
677
678         if (System.getProperty("Syslog.config.xml") != null)
679         {
680             // load the class manually so that we don't get this class
681
// depending on the XML things.
682
try
683             {
684                 Class JavaDoc config = Class.forName("com.protomatter.syslog.xml.SyslogXML");
685                 Method configure = config.getMethod("configure", new Class JavaDoc[] { File.class, String JavaDoc.class, Boolean.TYPE });
686                 configure.invoke(null,
687                     new Object JavaDoc[] { new File(System.getProperty("Syslog.config.xml")),
688                         System.getProperty("Syslog.xml.parser"), new Boolean JavaDoc(true) });
689             }
690             catch (Exception JavaDoc x)
691             {
692                 System.err.println(Syslog.getResourceString(MessageConstants.CANNOT_CONFIGURE_MESSAGE));
693                 x.printStackTrace();
694             }
695         }
696     }
697
698
699     /**
700      * Registers a new Syslogger object with Syslog.
701      *
702      *@param log The feature to be added to the Logger attribute
703      */

704     public final static synchronized void addLogger(Syslogger log)
705     {
706         loggers.add(log);
707         loggerArray = (Syslogger[])loggers.toArray(new Syslogger[0]);
708     }
709
710
711     /**
712      * Deregisters a Syslogger object from Syslog.
713      *
714      *@param log The logger to remove
715      *@return true if the logger was removed
716      */

717     public final static synchronized boolean removeLogger(Syslogger log)
718     {
719         if (loggers.contains(log))
720         {
721             loggers.remove(loggers.indexOf(log));
722             loggerArray = (Syslogger[])loggers.toArray(new Syslogger[0]);
723             return true;
724         }
725         return false;
726     }
727
728
729     /**
730      * Deregisters all Syslogger objects.
731      */

732     public final static synchronized void removeAllLoggers()
733     {
734         loggers = new ArrayList();
735         loggerArray = new Syslogger[0];
736     }
737
738
739     /**
740      * Returns an Enumeration of all Syslogger objects registered with Syslog.
741      *
742      *@return The loggers value
743      */

744     public final static Iterator getLoggers()
745     {
746         return loggers.iterator();
747     }
748
749
750     /**
751      * Remove all the loggers and shut them down. Waits for all background
752      * queues to finish processing work. Any new messages received immediately
753      * after this method is called (before it completes) will be ignored.
754      */

755     public static synchronized void shutdown()
756     {
757         // turn everything off.
758
masterSwitch = false;
759
760         // remove loggers just in case.
761
List list = loggers;
762         removeAllLoggers();
763
764         // wait for all background queues to shut down.
765
Iterator i = queueMap.keySet().iterator();
766         while (i.hasNext())
767         {
768             String JavaDoc queueName = (String JavaDoc)i.next();
769             WorkQueue queue = (WorkQueue)queueMap.get(queueName);
770             while ((queue.getQueueLength() > 0) || (queue.getNumWorkers() > 0))
771             {
772                 try
773                 {
774                     Thread.yield();
775                     Thread.sleep(100);
776                 }
777                 catch (InterruptedException JavaDoc x)
778                 {
779                     ; // who cares.
780
}
781             }
782         }
783
784         // shut 'em down. Loggers should flush and close files, etc.
785
i = list.iterator();
786         while (i.hasNext())
787         {
788             Syslogger l = (Syslogger)i.next();
789             l.shutdown();
790         }
791     }
792
793
794     /**
795      * Get a logger by name. If there are multiple loggers with the same name,
796      * the first one registered with that name will be returned. If there is no
797      * logger by that name, <tt>null</tt> is returned.
798      *
799      *@param name The name of the logger to get.
800      *@return The logger
801      */

802     public final static Syslogger getLogger(String JavaDoc name)
803     {
804         Iterator i = getLoggers();
805         Syslogger l = null;
806         while (i.hasNext())
807         {
808             l = (Syslogger)i.next();
809             if (l.getName() == null && name == null)
810             {
811                 return l;
812             }
813             if (l.getName() != null && name != null && l.getName().equals(name))
814             {
815                 return l;
816             }
817         }
818         return null;
819     }
820
821
822     /**
823      * Set the default mask for logging of messages. For example, to log all
824      * messages of type ERROR or greater, you would:
825      * Syslog.setLogMask(Syslog.atOrAbove(ERROR));
826      *
827      *@param mask The new logMask value
828      */

829     public final static void setLogMask(int mask)
830     {
831         if (mask == INHERIT_MASK)
832         {
833             throw new IllegalArgumentException JavaDoc(MessageFormat.format(
834                     getResourceString(MessageConstants.CANNOT_SET_MASK_MESSAGE),
835                     new Object JavaDoc[]{"INHERIT_MASK"}));
836         }
837         currentLogMask = mask;
838     }
839
840
841     /**
842      * Set the mask.
843      *
844      *@param mask The new logMask value
845      *@see #parseLogMask
846      */

847     public final static void setLogMask(String JavaDoc mask)
848     {
849         setLogMask(parseLogMask(mask));
850     }
851
852
853     /**
854      * Parse the mask. If the value passed in is the name of a level, like "
855      * <TT>INFO</TT> " or "<TT>WARNING</TT> " the mask will be set to <I>at or
856      * above</I> the listed level. If the string passed in is "<TT>INHERIT_MASK
857      * </TT>" then this policy will inherit the mask set in Syslog itself.<P>
858      *
859      * You can also pass in a list of levels, separated by commas and with an "
860      * <TT>=</TT> " before each level to select non-contiguous groups of
861      * levels. For instance, passing in "<TT>=INFO,=ERROR</TT> " will catch
862      * messages only at the <TT>INFO</TT> and <TT>ERROR</TT> levels, and <I>
863      * NOTHING ELSE</I> .
864      *
865      *@param mask String representation of the mask
866      *@return Computed log mask
867      */

868     public final static int parseLogMask(String JavaDoc mask)
869     {
870         if (mask.equals("DEBUG"))
871         {
872             return Syslog.atOrAbove(Syslog.DEBUG);
873         }
874         else if (mask.equals("INFO"))
875         {
876             return Syslog.atOrAbove(Syslog.INFO);
877         }
878         else if (mask.equals("WARNING"))
879         {
880             return Syslog.atOrAbove(Syslog.WARNING);
881         }
882         else if (mask.equals("ERROR"))
883         {
884             return Syslog.atOrAbove(Syslog.ERROR);
885         }
886         else if (mask.equals("FATAL"))
887         {
888             return Syslog.atOrAbove(Syslog.FATAL);
889         }
890         else if (mask.equals("INHERIT_MASK"))
891         {
892             return Syslog.INHERIT_MASK;
893         }
894         else if (mask.startsWith("="))
895         {
896             int newMask = 0;
897             StringTokenizer st = new StringTokenizer(mask, ", ");
898             while (st.hasMoreTokens())
899             {
900                 String JavaDoc elt = st.nextToken().substring(1);
901                 if (elt.equals("DEBUG"))
902                 {
903                     newMask |= Syslog.DEBUG;
904                 }
905                 else if (elt.equals("INFO"))
906                 {
907                     newMask |= Syslog.INFO;
908                 }
909                 else if (elt.equals("WARNING"))
910                 {
911                     newMask |= Syslog.WARNING;
912                 }
913                 else if (elt.equals("ERROR"))
914                 {
915                     newMask |= Syslog.ERROR;
916                 }
917                 else if (elt.equals("FATAL"))
918                 {
919                     newMask |= Syslog.FATAL;
920                 }
921             }
922             return newMask;
923         }
924         else
925         {
926             throw new IllegalArgumentException JavaDoc(getResourceString(MessageConstants.INVALID_MASK_MESSAGE));
927         }
928     }
929
930
931     /**
932      * Get a string representation of the current master log mask.
933      *
934      *@return The logMaskAsString value
935      */

936     public static String JavaDoc getLogMaskAsString()
937     {
938         return getLogMaskAsString(currentLogMask);
939     }
940
941
942     /**
943      * Get a string representation of the given log mask.
944      *
945      *@param logMask The parsed log mask
946      *@return The log mask rendered as a string
947      */

948     public static String JavaDoc getLogMaskAsString(int logMask)
949     {
950         if (logMask == Syslog.INHERIT_MASK)
951         {
952             return "INHERIT_MASK";
953         }
954         else if (logMask == Syslog.atOrAbove(Syslog.DEBUG))
955         {
956             return "DEBUG";
957         }
958         else if (logMask == Syslog.atOrAbove(Syslog.INFO))
959         {
960             return "INFO";
961         }
962         else if (logMask == Syslog.atOrAbove(Syslog.WARNING))
963         {
964             return "WARNING";
965         }
966         else if (logMask == Syslog.atOrAbove(Syslog.ERROR))
967         {
968             return "ERROR";
969         }
970         else if (logMask == Syslog.atOrAbove(Syslog.FATAL))
971         {
972             return "FATAL";
973         }
974
975         // bah... list of levels to pay attention to.
976
Vector list = new Vector(5);
977         if (inMask(Syslog.DEBUG, logMask))
978         {
979             list.addElement("=DEBUG");
980         }
981         if (inMask(Syslog.INFO, logMask))
982         {
983             list.addElement("=INFO");
984         }
985         if (inMask(Syslog.WARNING, logMask))
986         {
987             list.addElement("=WARNING");
988         }
989         if (inMask(Syslog.ERROR, logMask))
990         {
991             list.addElement("=ERROR");
992         }
993         if (inMask(Syslog.FATAL, logMask))
994         {
995             list.addElement("=FATAL");
996         }
997         StringBuffer JavaDoc b = new StringBuffer JavaDoc(32);
998         Enumeration e = list.elements();
999         while (e.hasMoreElements())
1000        {
1001            b.append(e.nextElement());
1002            if (e.hasMoreElements())
1003            {
1004                b.append(",");
1005            }
1006        }
1007        return b.toString();
1008    }
1009
1010
1011    /**
1012     * Check if the given level is covered by the given mask.
1013     *
1014     *@param level Log message severity
1015     *@param mask Log mask to compare it to
1016     *@return true if the given level is "in" the mask.
1017     */

1018    public final static boolean inMask(int level, int mask)
1019    {
1020        return ((level & mask) > 0);
1021    }
1022
1023
1024    /**
1025     * Get the default mask for logging of messages.
1026     *
1027     *@return The logMask value
1028     */

1029    public final static int getLogMask()
1030    {
1031        return currentLogMask;
1032    }
1033
1034
1035    /**
1036     *@param level The minimum severity of messages
1037     *@return the log mask for "all logs at or above this level"
1038     */

1039    public final static int atOrAbove(int level)
1040    {
1041        if (level == DEBUG)
1042        {
1043            return DEBUG | INFO | WARNING | ERROR | FATAL;
1044        }
1045        if (level == INFO)
1046        {
1047            return INFO | WARNING | ERROR | FATAL;
1048        }
1049        if (level == WARNING)
1050        {
1051            return WARNING | ERROR | FATAL;
1052        }
1053        if (level == ERROR)
1054        {
1055            return ERROR | FATAL;
1056        }
1057        if (level == FATAL)
1058        {
1059            return FATAL;
1060        }
1061        throw new IllegalArgumentException JavaDoc(
1062                MessageFormat.format(getResourceString(MessageConstants.ILLEGAL_ARGUMENT_MESSAGE),
1063                new Object JavaDoc[]{String.valueOf(level)}));
1064    }
1065
1066
1067    /**
1068     * Log a message. Logs to the <tt>DEFAULT_CHANNEL</tt> channel.
1069     *
1070     *@param host The machine the log entry originated on.
1071     *@param logger The object which is perfoming the log. It's class name
1072     * will be extracted and added to the log.
1073     *@param msg A short message describing the log entry.
1074     *@param detail A longer message with more information (can be null).
1075     *@param level The level of the log entry.
1076     */

1077    public final static void log(InetAddress host, Object JavaDoc logger, Object JavaDoc msg, Object JavaDoc detail, int level)
1078    {
1079        log(host, logger, null, msg, detail, level,
1080            Thread.currentThread(), Thread.currentThread().getName(),
1081            System.currentTimeMillis(), 1);
1082    }
1083
1084
1085    /**
1086     * Log a message. Logs to the <tt>DEFAULT_CHANNEL</tt> channel.
1087     *
1088     *@param logger The object which is perfoming the log. It's class name
1089     * will be extracted and added to the log.
1090     *@param msg A short message describing the log entry.
1091     *@param detail A longer message with more information (can be null).
1092     *@param level The level of the log entry.
1093     */

1094    public final static void log(Object JavaDoc logger, Object JavaDoc msg, Object JavaDoc detail, int level)
1095    {
1096        log(localHost, logger, null, msg, detail, level,
1097            Thread.currentThread(), Thread.currentThread().getName(),
1098            System.currentTimeMillis(), 1);
1099    }
1100
1101
1102    /**
1103     * Log a message. If <tt>detail</tt> is a subclass of <tt>Throwable</tt>
1104     * it's stack trace will be included in the output. If you want to log to a
1105     * channel other than <tt>DEFAULT_CHANNEL</tt> you will have to use this
1106     * method or one of the <tt><i>xxx</i> ToChannel(...)</tt> methods.
1107     *
1108     *@param logger The object which is perfoming the log. It's class name
1109     * will be extracted and added to the log.
1110     *@param channel The log channel to write to.
1111     *@param msg A short message describing the log entry.
1112     *@param detail A longer message with more information (can be null).
1113     *@param level The level of the log entry.
1114     */

1115    public final static void log(Object JavaDoc logger, Object JavaDoc channel,
1116        Object JavaDoc msg, Object JavaDoc detail, int level)
1117    {
1118        log(localHost, logger, channel, msg, detail, level,
1119            Thread.currentThread(), Thread.currentThread().getName(),
1120            System.currentTimeMillis(), 1);
1121    }
1122
1123
1124    /**
1125     * Log a message. If <tt>detail</tt> is a subclass of <tt>Throwable</tt>
1126     * it's stack trace will be included in the output. If you want to log to a
1127     * channel other than <tt>DEFAULT_CHANNEL</tt> you will have to use this
1128     * method or one of the <tt><i>xxx</i> ToChannel(...)</tt> methods.
1129     *
1130     *@param host The host the log message originated on.
1131     *@param logger The object which is perfoming the log. It's class name
1132     * will be extracted and added to the log.
1133     *@param channel The log channel to write to.
1134     *@param msg A short message describing the log entry.
1135     *@param detail A longer message with more information (can be null).
1136     *@param level The level of the log entry.
1137     */

1138    public final static void log(InetAddress host, Object JavaDoc logger, Object JavaDoc channel,
1139        Object JavaDoc msg, Object JavaDoc detail, int level)
1140    {
1141        log(host, logger, channel, msg, detail, level,
1142            Thread.currentThread(), Thread.currentThread().getName(),
1143            System.currentTimeMillis(), 1);
1144    }
1145
1146
1147    final static String JavaDoc[] convertChannelObject(Object JavaDoc channel)
1148    {
1149        if (channel == null)
1150        {
1151            return defaultChannelList;
1152        }
1153
1154        if (channel instanceof String JavaDoc)
1155        {
1156            return new String JavaDoc[]{(String JavaDoc)channel};
1157        }
1158        else if (channel instanceof String JavaDoc[])
1159        {
1160            return (String JavaDoc[])channel;
1161        }
1162        else if (channel instanceof Object JavaDoc[])
1163        {
1164            Object JavaDoc array[] = (Object JavaDoc[])channel;
1165            String JavaDoc channels[] = new String JavaDoc[array.length];
1166            for (int i = 0; i < array.length; i++)
1167            {
1168                channels[i] = array[i].toString();
1169            }
1170            return channels;
1171        }
1172
1173        return new String JavaDoc[]{channel.toString()};
1174    }
1175
1176
1177    /**
1178     * Log a message. <I>This method should not be called unless it's by a
1179     * remote log adapter.</I>
1180     *
1181     *@param host The host the log message originated on.
1182     *@param logger The object which is perfoming the log. It's class
1183     * name will be extracted and added to the log.
1184     *@param msg A short message describing the log entry.
1185     *@param detail A longer message with more information (can be
1186     * null).
1187     *@param level The level of the log entry.
1188     *@param thread The thread making the log call (null if remote)
1189     *@param threadName The name of the thread making the log call.
1190     *@param messageSendTime The time the message was sent.
1191     *@param incomingChannel Message channel
1192     */

1193    public final static void log(InetAddress host, Object JavaDoc logger,
1194        Object JavaDoc incomingChannel, Object JavaDoc msg, Object JavaDoc detail, int level,
1195        Thread JavaDoc thread, String JavaDoc threadName, long messageSendTime)
1196    {
1197        log(host, logger, incomingChannel, msg, detail, level,
1198            thread, threadName, messageSendTime, 1);
1199    }
1200
1201
1202    /**
1203     * Log a message. <I>This method should not be called unless it's by a
1204     * remote log adapter.</I>
1205     *
1206     *@param host The host the log message originated on.
1207     *@param logger The object which is perfoming the log. It's class
1208     * name will be extracted and added to the log.
1209     *@param msg A short message describing the log entry.
1210     *@param detail A longer message with more information (can be
1211     * null).
1212     *@param level The level of the log entry.
1213     *@param thread The thread making the log call (null if remote)
1214     *@param threadName The name of the thread making the log call.
1215     *@param messageSendTime The time the message was sent.
1216     *@param incomingChannel Channel
1217     *@param traceDepth Caller's depth in call stack, for computing
1218     * caller and method names at runtime.
1219     */

1220    public final static void log(InetAddress host, Object JavaDoc logger,
1221        Object JavaDoc incomingChannel, Object JavaDoc msg, Object JavaDoc detail, int level,
1222        Thread JavaDoc thread, String JavaDoc threadName, long messageSendTime,
1223        int traceDepth)
1224    {
1225        if (!masterSwitch)
1226        {
1227            return;
1228        }
1229
1230        String JavaDoc methodName = null;
1231        int lineNumber = StackTraceInfo.LINE_NUMBER_UNKNOWN;
1232        traceDepth++;
1233
1234        Class JavaDoc loggerClass = (logger == null) ? null : logger.getClass();
1235
1236        // get logger name
1237
String JavaDoc classname = null;
1238        if (!alwaysComputeCaller && !computeCaller)
1239        {
1240            if (logger == null)
1241            {
1242                classname = Q_MARK;
1243            }
1244            else
1245            {
1246                if (loggerClass == Class JavaDoc.class)
1247                {
1248                    classname = ((Class JavaDoc)logger).getName();
1249                }
1250                else if (loggerClass == String JavaDoc.class)
1251                {
1252                    classname = (String JavaDoc)logger;
1253                }
1254                else
1255                {
1256                    classname = logger.getClass().getName();
1257                }
1258            }
1259        }
1260
1261        // determine what channel(s) we should
1262
// send this log message to
1263
String JavaDoc channels[] = null;
1264        if (incomingChannel != null)
1265        { // specified channel in the call to log(...)
1266

1267            channels = convertChannelObject(incomingChannel);
1268        }
1269        else
1270        { // no channel(s) specified
1271

1272            // check if the logger is channel aware. If so,
1273
// ask it what channels it prefers.
1274
if (loggerClass == SyslogChannelAware.class)
1275            {
1276                channels = convertChannelObject(((SyslogChannelAware)logger).getSyslogChannel());
1277            }
1278            else
1279            {
1280                channels = defaultChannelList;
1281            }
1282        }
1283
1284        // then log to all objects in loggers
1285
int loggerIndex = 0;
1286        int channelIndex = channels.length;
1287        Syslogger[] localLoggerArray = loggerArray;
1288        int size = localLoggerArray.length;
1289        Syslogger log = null;
1290        SyslogMessage sm = null;
1291
1292        for (; --channelIndex >= 0; )
1293        {
1294            // outer loop is through the channel array
1295
sm = new SyslogMessage(host, messageSendTime,
1296                channels[channelIndex], logger,
1297                classname, msg, detail, level, thread, threadName,
1298                methodName, lineNumber);
1299            for (loggerIndex = size; --loggerIndex >= 0; )
1300            {
1301                // inner loop is through the loggers
1302
log = localLoggerArray[loggerIndex];
1303                try
1304                {
1305                    // should we compute the calling method
1306
if (alwaysComputeCaller && (sm.callingMethodName == null))
1307                    {
1308                        StackTraceInfo info = StackTraceUtil.whereAmI(traceDepth);
1309                        if (info != null)
1310                        {
1311                            sm.loggerClassname = info.className;
1312                            sm.callingMethodName = info.methodName;
1313                            sm.callingMethodLineNumber = info.lineNumber;
1314                        }
1315                    }
1316
1317                    if (log.getPolicy().shouldLog(sm))
1318                    {
1319                        // should we compute the calling method
1320
if (computeCaller && (sm.callingMethodName == null))
1321                        {
1322                            StackTraceInfo info = StackTraceUtil.whereAmI(traceDepth);
1323                            if (info != null)
1324                            {
1325                                sm.loggerClassname = info.className;
1326                                sm.callingMethodName = info.methodName;
1327                                sm.callingMethodLineNumber = info.lineNumber;
1328                            }
1329                        }
1330
1331                        log.log(sm);
1332                    }
1333                }
1334                catch (Throwable JavaDoc t)
1335                {
1336                    System.err.println(MessageFormat.format(
1337                            getResourceString(MessageConstants.WRITE_PROBLEM),
1338                            new Object JavaDoc[]{((log.getName() == null) ? log.toString() : log.getName()),
1339                            t.toString()}));
1340                    t.printStackTrace();
1341                }
1342            }
1343        }
1344    }
1345
1346
1347    /**
1348     * Logs an exception for the given object. The log level will be ERROR.
1349     *
1350     *@param host hostname
1351     *@param logger Calling object
1352     *@param e exception to log
1353     */

1354    public final static void log(InetAddress host, Object JavaDoc logger, Throwable JavaDoc e)
1355    {
1356        log(host, logger, null, e.toString(), e, ERROR,
1357            Thread.currentThread(), Thread.currentThread().getName(),
1358            System.currentTimeMillis(), 1);
1359    }
1360
1361
1362    /**
1363     * Logs an exception for the given object at a given level.
1364     *
1365     *@param host hostname
1366     *@param logger Calling object
1367     *@param e exception to log
1368     *@param level Severity to log the message at
1369     */

1370    public final static void log(InetAddress host, Object JavaDoc logger, Throwable JavaDoc e, int level)
1371    {
1372        log(host, logger, null, e.toString(), e, level,
1373            Thread.currentThread(), Thread.currentThread().getName(),
1374            System.currentTimeMillis(), 1);
1375    }
1376
1377
1378    /**
1379     * Logs an exception for the given object. The log level will be ERROR.
1380     *
1381     *@param logger Calling object
1382     *@param e Exception to log
1383     */

1384    public final static void log(Object JavaDoc logger, Throwable JavaDoc e)
1385    {
1386        log(localHost, logger, null, e.toString(), e, ERROR,
1387            Thread.currentThread(), Thread.currentThread().getName(),
1388            System.currentTimeMillis(), 1);
1389    }
1390
1391
1392    /**
1393     * Logs an exception for the given object at a given level.
1394     *
1395     *@param logger Calling object
1396     *@param e Exception to log
1397     *@param level Severity to log the message at
1398     */

1399    public final static void log(Object JavaDoc logger, Throwable JavaDoc e, int level)
1400    {
1401        log(localHost, logger, null, e.toString(), e, level,
1402            Thread.currentThread(), Thread.currentThread().getName(),
1403            System.currentTimeMillis(), 1);
1404    }
1405
1406
1407    /**
1408     * Logs a debug message, which will be converted through toString().
1409     *
1410     *@param host hostname
1411     *@param logger Calling object
1412     *@param message Message to log
1413     */

1414    public final static void debug(InetAddress host, Object JavaDoc logger, Object JavaDoc message)
1415    {
1416        log(host, logger, null, message, null, DEBUG);
1417        log(host, logger, null, message, null, DEBUG,
1418            Thread.currentThread(), Thread.currentThread().getName(),
1419            System.currentTimeMillis(), 1);
1420    }
1421
1422
1423    /**
1424     * Logs a debug message with a detail object, both of which will be
1425     * converted through toString().
1426     *
1427     *@param host hostname
1428     *@param logger Calling object
1429     *@param message Message to log
1430     *@param detail Extended message or exception
1431     */

1432    public final static void debug(InetAddress host, Object JavaDoc logger, Object JavaDoc message, Object JavaDoc detail)
1433    {
1434        log(host, logger, null, message, detail, DEBUG,
1435            Thread.currentThread(), Thread.currentThread().getName(),
1436            System.currentTimeMillis(), 1);
1437    }
1438
1439
1440    /**
1441     * Logs a debug message to the given channel.
1442     *
1443     *@param host hostname
1444     *@param logger Calling object
1445     *@param message Message to log
1446     */

1447    public final static void debugToChannel(InetAddress host, Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message)
1448    {
1449        log(host, logger, channel, message, null, DEBUG,
1450            Thread.currentThread(), Thread.currentThread().getName(),
1451            System.currentTimeMillis(), 1);
1452    }
1453
1454
1455    /**
1456     * Logs a debug message with a detail object to the given channel.
1457     *
1458     *@param host hostname
1459     *@param logger Calling object
1460     *@param channel Channel to log message on
1461     *@param message Message to log
1462     *@param detail Extended message or exception
1463     */

1464    public final static void debugToChannel(InetAddress host, Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message, Object JavaDoc detail)
1465    {
1466        log(host, logger, channel, message, detail, DEBUG,
1467            Thread.currentThread(), Thread.currentThread().getName(),
1468            System.currentTimeMillis(), 1);
1469    }
1470
1471
1472    /**
1473     * Logs a debug message, which will be converted through toString().
1474     *
1475     *@param logger Calling object
1476     *@param message Message to log
1477     */

1478    public final static void debug(Object JavaDoc logger, Object JavaDoc message)
1479    {
1480        log(localHost, logger, null, message, null, DEBUG,
1481            Thread.currentThread(), Thread.currentThread().getName(),
1482            System.currentTimeMillis(), 1);
1483    }
1484
1485
1486    /**
1487     * Logs a debug message with a detail object, both of which will be
1488     * converted through toString().
1489     *
1490     *@param logger Calling object
1491     *@param message Message to log
1492     *@param detail Extended message or exception
1493     */

1494    public final static void debug(Object JavaDoc logger, Object JavaDoc message, Object JavaDoc detail)
1495    {
1496        log(localHost, logger, null, message, detail, DEBUG,
1497            Thread.currentThread(), Thread.currentThread().getName(),
1498            System.currentTimeMillis(), 1);
1499    }
1500
1501
1502    /**
1503     * Logs a debug message to the given channel.
1504     *
1505     *@param logger Calling object
1506     *@param message Message to log
1507     *@param channel Channel to log message on
1508     */

1509    public final static void debugToChannel(Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message)
1510    {
1511        log(localHost, logger, channel, message, null, DEBUG,
1512            Thread.currentThread(), Thread.currentThread().getName(),
1513            System.currentTimeMillis(), 1);
1514    }
1515
1516
1517    /**
1518     * Logs a debug message with a detail object to the given channel.
1519     *
1520     *@param logger Calling object
1521     *@param channel Channel to log message on
1522     *@param message Message to log
1523     *@param detail Extended message or exception
1524     */

1525    public final static void debugToChannel(Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message, Object JavaDoc detail)
1526    {
1527        log(localHost, logger, channel, message, detail, DEBUG,
1528            Thread.currentThread(), Thread.currentThread().getName(),
1529            System.currentTimeMillis(), 1);
1530    }
1531
1532
1533
1534    /**
1535     * Logs a info message, which will be converted through toString().
1536     *
1537     *@param host Hostname
1538     *@param logger Calling object
1539     *@param message Message to log
1540     */

1541    public final static void info(InetAddress host, Object JavaDoc logger, Object JavaDoc message)
1542    {
1543        log(host, logger, null, message, null, INFO,
1544            Thread.currentThread(), Thread.currentThread().getName(),
1545            System.currentTimeMillis(), 1);
1546    }
1547
1548
1549    /**
1550     * Logs a info message with a detail object, both of which will be
1551     * converted through toString().
1552     *
1553     *@param host Hostname
1554     *@param logger Calling object
1555     *@param message Message to log
1556     *@param detail Extended message or exception
1557     */

1558    public final static void info(InetAddress host, Object JavaDoc logger, Object JavaDoc message, Object JavaDoc detail)
1559    {
1560        log(host, logger, null, message, detail, INFO,
1561            Thread.currentThread(), Thread.currentThread().getName(),
1562            System.currentTimeMillis(), 1);
1563    }
1564
1565
1566    /**
1567     * Logs an info message to the given channel.
1568     *
1569     *@param host Hostname
1570     *@param logger Calling object
1571     *@param channel Channel to log message on
1572     *@param message Message to log
1573     */

1574    public final static void infoToChannel(InetAddress host, Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message)
1575    {
1576        log(host, logger, channel, message, null, INFO,
1577            Thread.currentThread(), Thread.currentThread().getName(),
1578            System.currentTimeMillis(), 1);
1579    }
1580
1581
1582    /**
1583     * Logs an info message with a detail object to the given channel.
1584     *
1585     *@param host Hostname
1586     *@param logger Calling object
1587     *@param channel Channel to log message on
1588     *@param message Message to log
1589     *@param detail Extended message or exception
1590     */

1591    public final static void infoToChannel(InetAddress host, Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message, Object JavaDoc detail)
1592    {
1593        log(host, logger, channel, message, detail, INFO,
1594            Thread.currentThread(), Thread.currentThread().getName(),
1595            System.currentTimeMillis(), 1);
1596    }
1597
1598
1599    /**
1600     * Logs a info message, which will be converted through toString().
1601     *
1602     *@param logger Calling object
1603     *@param message Message to log
1604     */

1605    public final static void info(Object JavaDoc logger, Object JavaDoc message)
1606    {
1607        log(localHost, logger, null, message, null, INFO,
1608            Thread.currentThread(), Thread.currentThread().getName(),
1609            System.currentTimeMillis(), 1);
1610    }
1611
1612
1613    /**
1614     * Logs a info message with a detail object, both of which will be
1615     * converted through toString().
1616     *
1617     *@param logger Calling object
1618     *@param message Message to log
1619     *@param detail Extended message or exception
1620     */

1621    public final static void info(Object JavaDoc logger, Object JavaDoc message, Object JavaDoc detail)
1622    {
1623        log(localHost, logger, null, message, detail, INFO,
1624            Thread.currentThread(), Thread.currentThread().getName(),
1625            System.currentTimeMillis(), 1);
1626    }
1627
1628
1629    /**
1630     * Logs an info message to the given channel.
1631     *
1632     *@param logger Calling object
1633     *@param channel Channel to log message on
1634     *@param message Message to log
1635     */

1636    public final static void infoToChannel(Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message)
1637    {
1638        log(localHost, logger, channel, message, null, INFO,
1639            Thread.currentThread(), Thread.currentThread().getName(),
1640            System.currentTimeMillis(), 1);
1641    }
1642
1643
1644    /**
1645     * Logs an info message with a detail object to the given channel.
1646     *
1647     *@param logger Calling object
1648     *@param channel Channel to log message on
1649     *@param message Message to log
1650     *@param detail Extended message or exception
1651     */

1652    public final static void infoToChannel(Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message, Object JavaDoc detail)
1653    {
1654        log(localHost, logger, channel, message, detail, INFO,
1655            Thread.currentThread(), Thread.currentThread().getName(),
1656            System.currentTimeMillis(), 1);
1657    }
1658
1659
1660    /**
1661     * Logs a warning message, which will be converted through toString().
1662     *
1663     *@param host Hostname
1664     *@param logger Calling object
1665     *@param message Message to log
1666     */

1667    public final static void warning(InetAddress host, Object JavaDoc logger, Object JavaDoc message)
1668    {
1669        log(host, logger, null, message, null, WARNING,
1670            Thread.currentThread(), Thread.currentThread().getName(),
1671            System.currentTimeMillis(), 1);
1672    }
1673
1674
1675    /**
1676     * Logs a warning message with a detail object, both of which will be
1677     * converted through toString().
1678     *
1679     *@param host Hostname
1680     *@param logger Calling object
1681     *@param message Message to log
1682     *@param detail Extended message or exception
1683     */

1684    public final static void warning(InetAddress host, Object JavaDoc logger, Object JavaDoc message, Object JavaDoc detail)
1685    {
1686        log(host, logger, null, message, detail, WARNING,
1687            Thread.currentThread(), Thread.currentThread().getName(),
1688            System.currentTimeMillis(), 1);
1689    }
1690
1691
1692    /**
1693     * Logs a warning message to the given channel.
1694     *
1695     *@param host Hostname
1696     *@param logger Calling object
1697     *@param channel Channel to log message on
1698     *@param message Message to log
1699     */

1700    public final static void warningToChannel(InetAddress host, Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message)
1701    {
1702        log(host, logger, channel, message, null, WARNING,
1703            Thread.currentThread(), Thread.currentThread().getName(),
1704            System.currentTimeMillis(), 1);
1705    }
1706
1707
1708    /**
1709     * Logs a warning message with a detail object to the given channel.
1710     *
1711     *@param host Hostname
1712     *@param logger Calling object
1713     *@param channel Channel to log message on
1714     *@param message Message to log
1715     *@param detail Extended message or exception
1716     */

1717    public final static void warningToChannel(InetAddress host, Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message, Object JavaDoc detail)
1718    {
1719        log(host, logger, channel, message, detail, WARNING,
1720            Thread.currentThread(), Thread.currentThread().getName(),
1721            System.currentTimeMillis(), 1);
1722    }
1723
1724
1725    /**
1726     * Logs a warning message, which will be converted through toString().
1727     *
1728     *@param logger Calling object
1729     *@param message Message to log
1730     */

1731    public final static void warning(Object JavaDoc logger, Object JavaDoc message)
1732    {
1733        log(localHost, logger, null, message, null, WARNING,
1734            Thread.currentThread(), Thread.currentThread().getName(),
1735            System.currentTimeMillis(), 1);
1736    }
1737
1738
1739    /**
1740     * Logs a warning message with a detail object, both of which will be
1741     * converted through toString().
1742     *
1743     *@param logger Calling object
1744     *@param message Message to log
1745     *@param detail Extended message or exception
1746     */

1747    public final static void warning(Object JavaDoc logger, Object JavaDoc message, Object JavaDoc detail)
1748    {
1749        log(localHost, logger, null, message, detail, WARNING,
1750            Thread.currentThread(), Thread.currentThread().getName(),
1751            System.currentTimeMillis(), 1);
1752    }
1753
1754
1755    /**
1756     * Logs a warning message to the given channel.
1757     *
1758     *@param logger Calling object
1759     *@param channel Channel to log message on
1760     *@param message Message to log
1761     */

1762    public final static void warningToChannel(Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message)
1763    {
1764        log(localHost, logger, channel, message, null, WARNING,
1765            Thread.currentThread(), Thread.currentThread().getName(),
1766            System.currentTimeMillis(), 1);
1767    }
1768
1769
1770    /**
1771     * Logs a warning message with a detail object to the given channel.
1772     *
1773     *@param logger Calling object
1774     *@param channel Channel to log message on
1775     *@param message Message to log
1776     *@param detail Extended message or exception
1777     */

1778    public final static void warningToChannel(Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message, Object JavaDoc detail)
1779    {
1780        log(localHost, logger, channel, message, detail, WARNING,
1781            Thread.currentThread(), Thread.currentThread().getName(),
1782            System.currentTimeMillis(), 1);
1783    }
1784
1785
1786
1787    /**
1788     * Logs a error message, which will be converted through toString().
1789     *
1790     *@param host Hostname
1791     *@param logger Calling object
1792     *@param message Message to log
1793     */

1794    public final static void error(InetAddress host, Object JavaDoc logger, Object JavaDoc message)
1795    {
1796        log(host, logger, null, message, null, ERROR,
1797            Thread.currentThread(), Thread.currentThread().getName(),
1798            System.currentTimeMillis(), 1);
1799    }
1800
1801
1802    /**
1803     * Logs a error message with a detail object, both of which will be
1804     * converted through toString().
1805     *
1806     *@param host Hostname
1807     *@param logger Calling object
1808     *@param message Message to log
1809     *@param detail Extended message or exception
1810     */

1811    public final static void error(InetAddress host, Object JavaDoc logger, Object JavaDoc message, Object JavaDoc detail)
1812    {
1813        log(host, logger, null, message, detail, ERROR,
1814            Thread.currentThread(), Thread.currentThread().getName(),
1815            System.currentTimeMillis(), 1);
1816    }
1817
1818
1819    /**
1820     * Logs an error message to the given channel.
1821     *
1822     *@param host Hostname
1823     *@param logger Calling object
1824     *@param channel Channel to log message on
1825     *@param message Message to log
1826     */

1827    public final static void errorToChannel(InetAddress host, Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message)
1828    {
1829        log(host, logger, channel, message, null, ERROR,
1830            Thread.currentThread(), Thread.currentThread().getName(),
1831            System.currentTimeMillis(), 1);
1832    }
1833
1834
1835    /**
1836     * Logs an error message with a detail object to the given channel.
1837     *
1838     *@param host Hostname
1839     *@param logger Calling object
1840     *@param channel Channel to log message on
1841     *@param message Message to log
1842     *@param detail Extended message or exception
1843     */

1844    public final static void errorToChannel(InetAddress host, Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message, Object JavaDoc detail)
1845    {
1846        log(host, logger, channel, message, detail, ERROR,
1847            Thread.currentThread(), Thread.currentThread().getName(),
1848            System.currentTimeMillis(), 1);
1849    }
1850
1851
1852    /**
1853     * Logs a error message, which will be converted through toString().
1854     *
1855     *@param logger Calling object
1856     *@param message Message to log
1857     */

1858    public final static void error(Object JavaDoc logger, Object JavaDoc message)
1859    {
1860        log(localHost, logger, null, message, null, ERROR,
1861            Thread.currentThread(), Thread.currentThread().getName(),
1862            System.currentTimeMillis(), 1);
1863    }
1864
1865
1866    /**
1867     * Logs a error message with a detail object, both of which will be
1868     * converted through toString().
1869     *
1870     *@param logger Calling object
1871     *@param message Message to log
1872     *@param detail Extended message or exception
1873     */

1874    public final static void error(Object JavaDoc logger, Object JavaDoc message, Object JavaDoc detail)
1875    {
1876        log(localHost, logger, null, message, detail, ERROR,
1877            Thread.currentThread(), Thread.currentThread().getName(),
1878            System.currentTimeMillis(), 1);
1879    }
1880
1881
1882    /**
1883     * Logs an error message to the given channel.
1884     *
1885     *@param logger Calling object
1886     *@param channel Channel to log message on
1887     *@param message Message to log
1888     */

1889    public final static void errorToChannel(Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message)
1890    {
1891        log(localHost, logger, channel, message, null, ERROR,
1892            Thread.currentThread(), Thread.currentThread().getName(),
1893            System.currentTimeMillis(), 1);
1894    }
1895
1896
1897    /**
1898     * Logs an error message with a detail object to the given channel.
1899     *
1900     *@param logger Calling object
1901     *@param channel Channel to log message on
1902     *@param message Message to log
1903     *@param detail Extended message or exception
1904     */

1905    public final static void errorToChannel(Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message, Object JavaDoc detail)
1906    {
1907        log(localHost, logger, channel, message, detail, ERROR,
1908            Thread.currentThread(), Thread.currentThread().getName(),
1909            System.currentTimeMillis(), 1);
1910    }
1911
1912
1913
1914    /**
1915     * Logs a fatal message, which will be converted through toString().
1916     *
1917     *@param host Hostname
1918     *@param logger Calling object
1919     *@param message Message to log
1920     */

1921    public final static void fatal(InetAddress host, Object JavaDoc logger, Object JavaDoc message)
1922    {
1923        log(host, logger, null, message, null, FATAL,
1924            Thread.currentThread(), Thread.currentThread().getName(),
1925            System.currentTimeMillis(), 1);
1926    }
1927
1928
1929    /**
1930     * Logs a fatal message with a detail object, both of which will be
1931     * converted through toString().
1932     *
1933     *@param host Hostname
1934     *@param logger Calling object
1935     *@param message Message to log
1936     *@param detail Extended message or exception
1937     */

1938    public final static void fatal(InetAddress host, Object JavaDoc logger, Object JavaDoc message, Object JavaDoc detail)
1939    {
1940        log(host, logger, null, message, detail, FATAL,
1941            Thread.currentThread(), Thread.currentThread().getName(),
1942            System.currentTimeMillis(), 1);
1943    }
1944
1945
1946    /**
1947     * Logs a fatal message to the given channel.
1948     *
1949     *@param host Hostname
1950     *@param logger Calling object
1951     *@param channel Channel to log message on
1952     *@param message Message to log
1953     */

1954    public final static void fatalToChannel(InetAddress host, Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message)
1955    {
1956        log(host, logger, channel, message, null, FATAL,
1957            Thread.currentThread(), Thread.currentThread().getName(),
1958            System.currentTimeMillis(), 1);
1959    }
1960
1961
1962    /**
1963     * Logs a fatal message with a detail object to the given channel.
1964     *
1965     *@param host Hostname
1966     *@param logger Calling object
1967     *@param channel Channel to log message on
1968     *@param message Message to log
1969     *@param detail Extended message or exception
1970     */

1971    public final static void fatalToChannel(InetAddress host, Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message, Object JavaDoc detail)
1972    {
1973        log(host, logger, channel, message, detail, FATAL,
1974            Thread.currentThread(), Thread.currentThread().getName(),
1975            System.currentTimeMillis(), 1);
1976    }
1977
1978
1979    /**
1980     * Logs a fatal message, which will be converted through toString().
1981     *
1982     *@param logger Calling object
1983     *@param message Message to log
1984     */

1985    public final static void fatal(Object JavaDoc logger, Object JavaDoc message)
1986    {
1987        log(localHost, logger, null, message, null, FATAL,
1988            Thread.currentThread(), Thread.currentThread().getName(),
1989            System.currentTimeMillis(), 1);
1990    }
1991
1992
1993    /**
1994     * Logs a fatal message with a detail object, both of which will be
1995     * converted through toString().
1996     *
1997     *@param logger Calling object
1998     *@param message Message to log
1999     *@param detail Extended message or exception
2000     */

2001    public final static void fatal(Object JavaDoc logger, Object JavaDoc message, Object JavaDoc detail)
2002    {
2003        log(localHost, logger, null, message, detail, FATAL,
2004            Thread.currentThread(), Thread.currentThread().getName(),
2005            System.currentTimeMillis(), 1);
2006    }
2007
2008
2009    /**
2010     * Logs a fatal message to the given channel.
2011     *
2012     *@param logger Calling object
2013     *@param channel Channel to log message on
2014     *@param message Message to log
2015     */

2016    public final static void fatalToChannel(Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message)
2017    {
2018        log(localHost, logger, channel, message, null, FATAL,
2019            Thread.currentThread(), Thread.currentThread().getName(),
2020            System.currentTimeMillis(), 1);
2021    }
2022
2023
2024    /**
2025     * Logs a fatal message with a detail object to the given channel.
2026     *
2027     *@param logger Calling object
2028     *@param channel Channel to log message on
2029     *@param message Message to log
2030     *@param detail Extended message or exception
2031     */

2032    public final static void fatalToChannel(Object JavaDoc logger, Object JavaDoc channel, Object JavaDoc message, Object JavaDoc detail)
2033    {
2034        log(localHost, logger, channel, message, detail, FATAL,
2035            Thread.currentThread(), Thread.currentThread().getName(),
2036            System.currentTimeMillis(), 1);
2037    }
2038
2039
2040    /**
2041     * Logs a breadcrumb at the debug level. The breadcrumb
2042     * includes information from a <tt><a HREF="../util/StackTraceInfo.html">StackTraceInfo</a></tt>
2043     * object.
2044     */

2045    public final static void crumb()
2046    {
2047        StackTraceInfo trace = StackTraceUtil.whereAmI(1);
2048        log(localHost, trace.className, null,
2049            MessageFormat.format(getResourceString(MessageConstants.CRUMB_MESSAGE),
2050            new Object JavaDoc[] { trace }),
2051            (Object JavaDoc)null, DEBUG, Thread.currentThread(), Thread.currentThread().getName(),
2052            System.currentTimeMillis(), 1);
2053    }
2054
2055    /**
2056     * Logs a breadcrumb at the debug level. The breadcrumb
2057     * includes information from a <tt><a HREF="../util/StackTraceInfo.html">StackTraceInfo</a></tt>
2058     * object.
2059     */

2060    public final static void crumb(Object JavaDoc logger)
2061    {
2062        log(localHost, logger, (Object JavaDoc)null,
2063            MessageFormat.format(getResourceString(MessageConstants.CRUMB_MESSAGE),
2064            new Object JavaDoc[] { Syslog.whereAmI(1) }),
2065            (Object JavaDoc)null, DEBUG, Thread.currentThread(), Thread.currentThread().getName(),
2066            System.currentTimeMillis(), 1);
2067    }
2068
2069    /**
2070     * Logs a breadcrumb at the debug level.
2071     */

2072    public final static void crumb(Object JavaDoc logger, Object JavaDoc channel)
2073    {
2074        log(localHost, logger, channel,
2075            MessageFormat.format(getResourceString(MessageConstants.CRUMB_MESSAGE),
2076            new Object JavaDoc[] { Syslog.whereAmI(1) }),
2077            null, DEBUG, Thread.currentThread(), Thread.currentThread().getName(),
2078            System.currentTimeMillis(), 1);
2079    }
2080
2081    static String JavaDoc whereAmI(int depth)
2082    {
2083        StackTraceInfo trace = StackTraceUtil.whereAmI(depth +1);
2084        return trace.toString();
2085    }
2086
2087    /**
2088     * Determine if the current default syslog mask would allow the given level
2089     * of message to be logged. This is not an absolute method of determining
2090     * if a message would be logged by some registered logger. If there is a
2091     * registered logger who is not inheriting the mask from <tt>Syslog</tt>
2092     * itself, it may (or may not) have logged the message.
2093     *
2094     *@param level Message severity to test
2095     *@return True if it is likely to be logged
2096     *@deprecated
2097     */

2098    public final static boolean canLog(int level)
2099    {
2100        return inMask(level, currentLogMask);
2101    }
2102
2103
2104    /**
2105     * Determine if the current syslog mask would allow a message at the <tt>
2106     * DEBUG</tt> level to be logged.
2107     *
2108     *@return True if it is likely to be logged
2109     *@deprecated
2110     */

2111    public final static boolean canDebug()
2112    {
2113        return canLog(DEBUG);
2114    }
2115
2116
2117    /**
2118     * Determine if the current syslog mask would allow a message at the <tt>
2119     * INFO</tt> level to be logged.
2120     *
2121     *@return True if it is likely to be logged
2122     *@deprecated
2123     */

2124    public final static boolean canInfo()
2125    {
2126        return canLog(INFO);
2127    }
2128
2129
2130    /**
2131     * Determine if the current syslog mask would allow a message at the <tt>
2132     * WARNING</tt> level to be logged.
2133     *
2134     *@return True if it is likely to be logged
2135     *@deprecated
2136     */

2137    public final static boolean canWarning()
2138    {
2139        return canLog(WARNING);
2140    }
2141
2142
2143    /**
2144     * Determine if the current syslog mask would allow a message at the <tt>
2145     * ERROR</tt> level to be logged.
2146     *
2147     *@return True if it is likely to be logged
2148     *@see #canLog(int)
2149     *@deprecated
2150     */

2151    public final static boolean canError()
2152    {
2153        return canLog(ERROR);
2154    }
2155
2156
2157    /**
2158     * Determine if the current syslog mask would allow a message at the <tt>
2159     * FATAL</tt> level to be logged.
2160     *
2161     *@return True if it is likely to be logged
2162     *@see #canLog(int)
2163     *@deprecated
2164     */

2165    public final static boolean canFatal()
2166    {
2167        return canLog(FATAL);
2168    }
2169
2170
2171    /**
2172     * Determine if it's likely that someone will listen to a message from the
2173     * given logger at the given level.
2174     *
2175     *@param logger Calling object
2176     *@return True if it is likely to be logged
2177     *@see #mightLog(Object, int, Object)
2178     *@deprecated
2179     */

2180    public final static boolean mightLog(Object JavaDoc logger, int level)
2181    {
2182        return mightLog(logger, level, null);
2183    }
2184
2185
2186    /**
2187     * Determine if it's likely that someone will listen to a debug message
2188     * from the given logger.
2189     *
2190     *@param logger Calling object
2191     *@return True if it is likely to be logged
2192     *@see #mightLog(Object, int, Object)
2193     *@deprecated
2194     */

2195    public final static boolean mightDebug(Object JavaDoc logger)
2196    {
2197        return mightLog(logger, DEBUG, null);
2198    }
2199
2200
2201    /**
2202     * Determine if it's likely that someone will listen to an info message
2203     * from the given logger.
2204     *
2205     *@param logger Calling object
2206     *@return True if it is likely to be logged
2207     *@see #mightLog(Object, int, Object)
2208     *@deprecated
2209     */

2210    public final static boolean mightInfo(Object JavaDoc logger)
2211    {
2212        return mightLog(logger, INFO, null);
2213    }
2214
2215
2216    /**
2217     * Determine if it's likely that someone will listen to a warning message
2218     * from the given logger.
2219     *
2220     *@param logger Calling object
2221     *@return True if it is likely to be logged
2222     *@see #mightLog(Object, int, Object)
2223     *@deprecated
2224     */

2225    public final static boolean mightWarning(Object JavaDoc logger)
2226    {
2227        return mightLog(logger, WARNING, null);
2228    }
2229
2230
2231    /**
2232     * Determine if it's likely that someone will listen to an error message
2233     * from the given logger.
2234     *
2235     *@param logger Calling object
2236     *@return True if it is likely to be logged
2237     *@see #mightLog(Object, int, Object)
2238     *@deprecated
2239     */

2240    public final static boolean mightError(Object JavaDoc logger)
2241    {
2242        return mightLog(logger, ERROR, null);
2243    }
2244
2245
2246    /**
2247     * Determine if it's likely that someone will listen to a fatal message
2248     * from the given logger.
2249     *
2250     *@param logger Calling object
2251     *@return True if it is likely to be logged
2252     *@see #mightLog(Object, int, Object)
2253     *@deprecated
2254     */

2255    public final static boolean mightFatal(Object JavaDoc logger)
2256    {
2257        return mightLog(logger, FATAL, null);
2258    }
2259
2260
2261    /**
2262     * Determine if it's likely that someone will listen to a debug message
2263     * from the given logger on the given channel(s).
2264     *
2265     *@param logger Calling object
2266     *@param channel Channel name or list
2267     *@return True if it is likely to be logged
2268     *@see #mightLog(Object, int, Object)
2269     *@deprecated
2270     */

2271    public final static boolean mightDebug(Object JavaDoc logger, Object JavaDoc channel)
2272    {
2273        return mightLog(logger, DEBUG, channel);
2274    }
2275
2276
2277    /**
2278     * Determine if it's likely that someone will listen to an info message
2279     * from the given logger on the given channel(s).
2280     *
2281     *@param logger Calling object
2282     *@param channel Channel name or list
2283     *@return True if it is likely to be logged
2284     *@see #mightLog(Object, int, Object)
2285     *@deprecated
2286     */

2287    public final static boolean mightInfo(Object JavaDoc logger, Object JavaDoc channel)
2288    {
2289        return mightLog(logger, INFO, channel);
2290    }
2291
2292
2293    /**
2294     * Determine if it's likely that someone will listen to a warning message
2295     * from the given logger on the given channel(s).
2296     *
2297     *@param logger Calling object
2298     *@param channel Channel name or list
2299     *@return True if it is likely to be logged
2300     *@see #mightLog(Object, int, Object)
2301     *@deprecated
2302     */

2303    public final static boolean mightWarning(Object JavaDoc logger, Object JavaDoc channel)
2304    {
2305        return mightLog(logger, WARNING, channel);
2306    }
2307
2308
2309    /**
2310     * Determine if it's likely that someone will listen to an error message
2311     * from the given logger on the given channel(s).
2312     *
2313     *@param logger Calling object
2314     *@param channel Channel name or list
2315     *@return True if it is likely to be logged
2316     *@see #mightLog(Object, int, Object)
2317     *@deprecated
2318     */

2319    public final static boolean mightError(Object JavaDoc logger, Object JavaDoc channel)
2320    {
2321        return mightLog(logger, ERROR, channel);
2322    }
2323
2324
2325    /**
2326     * Determine if it's likely that someone will listen to a fatal message
2327     * from the given logger on the given channel(s).
2328     *
2329     *@param logger Calling object
2330     *@param channel Channel name or list
2331     *@return True if it is likely to be logged
2332     *@see #mightLog(Object, int, Object)
2333     *@deprecated
2334     */

2335    public final static boolean mightFatal(Object JavaDoc logger, Object JavaDoc channel)
2336    {
2337        return mightLog(logger, FATAL, channel);
2338    }
2339
2340
2341    /**
2342     * This method has been deprecated. You should use the
2343     * <tt><a HREF="../util/Debug.html">com.protomatter.util.Debug</a></tt>
2344     * class instead.
2345     *
2346     *@param logger Calling object
2347     *@param level Message severity
2348     *@param channel Channel to log message on
2349     *@return True if it is likely to be logged
2350     *@deprecated
2351     */

2352    public final static boolean mightLog(Object JavaDoc logger, int level, Object JavaDoc channel)
2353    {
2354        int theLevel = level;
2355        Object JavaDoc theLogger = logger;
2356
2357        // determine channel list.
2358
if (channel == null)
2359        {
2360            if (logger instanceof SyslogChannelAware)
2361            {
2362                channel = ((SyslogChannelAware)logger).getSyslogChannel();
2363            }
2364            else
2365            {
2366                channel = new Object JavaDoc[]{DEFAULT_CHANNEL};
2367            }
2368        }
2369
2370        // make up a nice list of channels.
2371
String JavaDoc[] list = null;
2372        if (channel instanceof String JavaDoc)
2373        {
2374            list = new String JavaDoc[]{(String JavaDoc)channel};
2375        }
2376        else if (channel instanceof String JavaDoc[])
2377        {
2378            list = (String JavaDoc[])channel;
2379        }
2380
2381        // ask each logger if they care.
2382
int i = loggers.size();
2383        int j = 0;
2384        Syslogger l = null;
2385        for (; --i >= 0; )
2386        {
2387            l = (Syslogger)loggers.get(i);
2388            for (j = list.length; --j >= 0; )
2389            {
2390                if (l.mightLog(theLogger, level, list[j]))
2391                {
2392                    return true;
2393                } // somebody cares
2394
}
2395        }
2396
2397        // nobody wants it.
2398
return false;
2399    }
2400
2401
2402    /**
2403     * Pass-through to <TT>mightLog(Object logger, int level)</TT> .
2404     *
2405     *@param logger Calling object
2406     *@param level Message severity
2407     *@return True if it is likely to be logged
2408     *@see #mightLog(Object, int)
2409     *@deprecated
2410     */

2411    public final static boolean canLog(Object JavaDoc logger, int level)
2412    {
2413        return mightLog(logger, level);
2414    }
2415
2416
2417    /**
2418     * Pass-through to <TT>mightDebug(Object logger)</TT> .
2419     *
2420     *@param logger Calling object
2421     *@return True if it is likely to be logged
2422     *@deprecated
2423     *@see #mightDebug(Object)
2424     */

2425    public final static boolean canDebug(Object JavaDoc logger)
2426    {
2427        return canLog(logger, DEBUG);
2428    }
2429
2430
2431    /**
2432     * Pass-through to <TT>mightInfo(Object logger)</TT> .
2433     *
2434     *@param logger Calling object
2435     *@return True if it is likely to be logged
2436     *@deprecated
2437     *@see #mightInfo(Object)
2438     */

2439    public final static boolean canInfo(Object JavaDoc logger)
2440    {
2441        return canLog(logger, INFO);
2442    }
2443
2444
2445    /**
2446     * Pass-through to <TT>mightWarning(Object logger)</TT> .
2447     *
2448     *@param logger Calling object
2449     *@return True if it is likely to be logged
2450     *@deprecated
2451     *@see #mightWarning(Object)
2452     */

2453    public final static boolean canWarning(Object JavaDoc logger)
2454    {
2455        return canLog(logger, WARNING);
2456    }
2457
2458
2459    /**
2460     * Pass-through to <TT>mightError(Object logger)</TT> .
2461     *
2462     *@param logger Calling object
2463     *@return True if it is likely to be logged
2464     *@deprecated
2465     *@see #mightError(Object)
2466     */

2467    public final static boolean canError(Object JavaDoc logger)
2468    {
2469        return canLog(logger, ERROR);
2470    }
2471
2472
2473    /**
2474     * Pass-through to <TT>mightFatal(Object logger)</TT> .
2475     *
2476     *@param logger Calling object
2477     *@return True if it is likely to be logged
2478     *@deprecated
2479     *@see #mightFatal(Object)
2480     */

2481    public final static boolean canFatal(Object JavaDoc logger)
2482    {
2483        return canLog(logger, FATAL);
2484    }
2485
2486
2487    /**
2488     * Flush output to all loggers.
2489     */

2490    public static void flush()
2491    {
2492        // run through the loggers and have them each
2493
// flush their output.
2494
Iterator i = Syslog.getLoggers();
2495        while (i.hasNext())
2496        {
2497            Syslogger logger = (Syslogger)i.next();
2498            try
2499            {
2500                logger.flush();
2501            }
2502            catch (Throwable JavaDoc t)
2503            {
2504                System.err.println(MessageFormat.format(
2505                        getResourceString(MessageConstants.FLUSH_PROBLEM_MESSAGE),
2506                        new Object JavaDoc[]{logger.getName(), t.toString()}));
2507                t.printStackTrace();
2508            }
2509        }
2510    }
2511
2512
2513    /**
2514     * Get the resource bundle associated with Syslog.
2515     *
2516     *@return The resources value
2517     */

2518    public final static ResourceBundle getResources()
2519    {
2520        return resources;
2521    }
2522
2523
2524    /**
2525     * Get the value of the given resource name associated with Syslog.
2526     *
2527     *@param name Resource name to get
2528     *@return The resourceString value
2529     */

2530    public final static String JavaDoc getResourceString(String JavaDoc name)
2531    {
2532        return getResources().getString(name);
2533    }
2534
2535
2536    private static class SyslogFlushThread
2537             extends Thread JavaDoc
2538    {
2539        private long sleepInterval;
2540        private boolean stop = false;
2541
2542
2543        public SyslogFlushThread(long sleepInterval)
2544        {
2545            super(Syslog.getResourceString(MessageConstants.FLUSH_THREAD_NAME_MESSAGE));
2546            setDaemon(true);
2547            this.sleepInterval = sleepInterval;
2548        }
2549
2550
2551        public long getSleepInterval()
2552        {
2553            return this.sleepInterval;
2554        }
2555
2556
2557        public void stopRunning()
2558        {
2559            this.stop = true;
2560        }
2561
2562
2563        public void run()
2564        {
2565            while (true && !stop)
2566            {
2567                Syslog.flush();
2568                try
2569                {
2570                    Thread.sleep(sleepInterval);
2571                }
2572                catch (InterruptedException JavaDoc x)
2573                {
2574                    ;
2575                }
2576            }
2577        }
2578    }
2579}
2580
2581
Popular Tags