KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > utility > logging > AbstractLogger


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * AbstractLogger.java
26  *
27  * Created on May 14, 2002, 12:35 PM
28  */

29
30 package com.sun.jdo.spi.persistence.utility.logging;
31
32 import java.io.*;
33 import java.util.*;
34 import java.text.MessageFormat JavaDoc;
35
36 import com.sun.jdo.spi.persistence.utility.I18NHelper;
37 import com.sun.jdo.spi.persistence.utility.StringHelper;
38
39 /**
40  * This class provides a default implementation of the
41  * com.sun.jdo.spi.persistence.utility.logging.Logger interface which
42  * implements most methods and/or delegates them to a few
43  * abstract methods which subclasses must override.
44  *
45  * @author Rochelle Raccah
46  * @version %I%
47  */

48 abstract public class AbstractLogger implements Logger
49 {
50     /** I18N message handler for this class */
51     private static final ResourceBundle _messages =
52         I18NHelper.loadBundle(AbstractLogger.class);
53
54     /** Default level if none supplied */
55     private static final int _defaultLevel = INFO;
56
57     /** Level Separator for Logger Level specification */
58     private static final char _levelSeparator='.';
59
60     private static Map _levelNamesToValues;
61
62     private static boolean _hasLoggingProperties = true;
63     private static Properties _loggingProperties;
64
65     /** Resource bundle for this (named) logger */
66     private final ResourceBundle _bundle;
67
68     /** Name for this logger */
69     private final String JavaDoc _loggerName;
70
71     /** Level for this logger */
72     private final int _level;
73
74     static
75     {
76         _levelNamesToValues = new HashMap();
77         _levelNamesToValues.put("ALL", new Integer JavaDoc(ALL)); // NOI18N
78
_levelNamesToValues.put("FINEST", new Integer JavaDoc(FINEST)); // NOI18N
79
_levelNamesToValues.put("FINER", new Integer JavaDoc(FINER)); // NOI18N
80
_levelNamesToValues.put("FINE", new Integer JavaDoc(FINE)); // NOI18N
81
_levelNamesToValues.put("CONFIG", new Integer JavaDoc(CONFIG)); // NOI18N
82
_levelNamesToValues.put("INFO", new Integer JavaDoc(INFO)); // NOI18N
83
_levelNamesToValues.put("WARNING", new Integer JavaDoc(WARNING)); // NOI18N
84
_levelNamesToValues.put("SEVERE", new Integer JavaDoc(SEVERE)); // NOI18N
85
_levelNamesToValues.put("OFF", new Integer JavaDoc(OFF)); // NOI18N
86
}
87
88     /** Creates a new AbstractLogger. The supplied class loader or the
89      * loader which loaded this class must be able to load the bundle.
90      * @param loggerName the full domain name of this logger
91      * @param bundleName the bundle name for message translation
92      * @param loader the loader used for looking up the bundle file
93      * and possibly the logging.properties or alternative file
94      */

95     public AbstractLogger (String JavaDoc loggerName, String JavaDoc bundleName,
96         ClassLoader JavaDoc loader)
97     {
98         _loggerName = loggerName;
99         _level = readLoggingLevel(loggerName);
100         _bundle = I18NHelper.loadBundle(bundleName, loader);
101     }
102
103     /** Get the message bundle for the AbstractLogger itself.
104      */

105     protected static ResourceBundle getMessages () { return _messages; }
106
107     private static Map getLevelNameMap () { return _levelNamesToValues; }
108
109     // mostly copied from LogManager's readConfiguration() in jdk1.4
110
private static synchronized Properties getLoggingProperties ()
111     {
112         if (_hasLoggingProperties && (_loggingProperties == null))
113         {
114             String JavaDoc fileName =
115                 System.getProperty("java.util.logging.config.file"); // NOI18N
116

117             if (fileName == null)
118             {
119                 fileName = System.getProperty("java.home"); // NOI18N
120

121                 if (fileName != null)
122                 {
123                     File file = new File(fileName, "lib"); // NOI18N
124

125                     file = new File(file, "logging.properties"); // NOI18N
126

127                     try
128                     {
129                         fileName = file.getCanonicalPath();
130                     }
131                     catch (IOException ioe)
132                     {
133                         fileName = null;
134                     }
135                 }
136             }
137
138             if (fileName != null)
139             {
140                 InputStream inputStream = null;
141                 File file = null;
142
143                 try
144                 {
145                     Properties properties = new Properties();
146                     BufferedInputStream bufferedInputStream = null;
147
148                     inputStream = new FileInputStream(fileName);
149                     bufferedInputStream = new BufferedInputStream(inputStream);
150                     properties.load(bufferedInputStream);
151                     _loggingProperties = properties;
152                 }
153                 catch (Exception JavaDoc e)
154                 {
155                     _hasLoggingProperties = false;
156                 }
157                 finally
158                 {
159                     if (inputStream != null)
160                     {
161                         try
162                         {
163                             inputStream.close();
164                         }
165                         catch (IOException ioe)
166                         {
167                             // couldn't close it for some reason
168
}
169                     }
170                 }
171             }
172             else
173                 _hasLoggingProperties = false;
174         }
175
176         return _loggingProperties;
177     }
178
179     /** Return the string name of a level given its int value.
180      * @return a string representing the level
181      */

182     public static String JavaDoc toString (int level)
183     {
184         String JavaDoc bundleKey = null;
185
186         switch (level)
187         {
188             case Logger.OFF:
189                 bundleKey = "utility.level_off"; // NOI18N
190
break;
191             case Logger.SEVERE:
192                 bundleKey = "utility.level_severe"; // NOI18N
193
break;
194             case Logger.WARNING:
195                 bundleKey = "utility.level_warning"; // NOI18N
196
break;
197             case Logger.INFO:
198                 bundleKey = "utility.level_info"; // NOI18N
199
break;
200             case Logger.CONFIG:
201                 bundleKey = "utility.level_config"; // NOI18N
202
break;
203             case Logger.FINE:
204                 bundleKey = "utility.level_fine"; // NOI18N
205
break;
206             case Logger.FINER:
207                 bundleKey = "utility.level_finer"; // NOI18N
208
break;
209             case Logger.FINEST:
210                 bundleKey = "utility.level_finest"; // NOI18N
211
break;
212             case Logger.ALL:
213                 bundleKey = "utility.level_all"; // NOI18N
214
break;
215         }
216
217         return ((bundleKey != null) ?
218             I18NHelper.getMessage(getMessages(), bundleKey) : null);
219     }
220
221     /** Get the message bundle for the named instance of the logger.
222      */

223     protected ResourceBundle getBundle () { return _bundle; }
224
225     public int getLevel () { return _level; }
226
227     private int readLoggingLevel (String JavaDoc loggerName)
228     {
229         String JavaDoc value = findLevelMatch(loggerName);
230         int level = _defaultLevel;
231
232         if (value != null)
233         {
234             Object JavaDoc lookupValue = null;
235
236             value = value.trim();
237             lookupValue = getLevelNameMap().get(value);
238
239             if (lookupValue != null)
240                 level = ((Integer JavaDoc)lookupValue).intValue();
241             else // maybe a number was specified
242
{
243                 try
244                 {
245                     level = Integer.parseInt(value);
246                 }
247                 catch (NumberFormatException JavaDoc nfe)
248                 {
249                     // level will be the default
250
}
251             }
252         }
253
254         return level;
255     }
256
257     /** Find the best matched logging level from the logging properties
258      *@param loggerName the name of the hierarchical
259      *@return a String representing the level value
260      */

261     private String JavaDoc findLevelMatch (String JavaDoc loggerName)
262     {
263         Properties properties = getLoggingProperties();
264         String JavaDoc value = null;
265
266         if (properties != null)
267         {
268             while (value == null)
269             {
270                 int lastIndex = loggerName.lastIndexOf(_levelSeparator);
271
272                 value = properties.getProperty(loggerName + ".level"); // NOI18N
273

274                 if (loggerName.trim().length() > 0)
275                 {
276                     loggerName = ((lastIndex == -1) ? "" : // NOI18N
277
loggerName.substring(0, lastIndex));
278                 }
279                 else
280                     return value;
281             }
282         }
283
284         return value;
285     }
286
287     /** Return whether logging is enabled at the FINE level. This method
288      * is not exact because to make it accurately reflect the logging level
289      * we would have to include the JDK 1.4 java.util.logging.Level class.
290      * This method does not delegate to isLoggable(FINE) for performance
291      * reasons.
292      * @return whether logging is enabled at the fine level.
293      */

294     public boolean isLoggable () { return (FINE >= getLevel()); }
295
296     /**
297      * Check if a message of the given level would actually be logged
298      * by this logger. This check is based on the Logger's effective level,
299      * which may be inherited from its parent.
300      *
301      * @return true if the given message level is currently being logged.
302      * @param levelValue the level to check
303      */

304     public boolean isLoggable (int levelValue)
305     {
306         return (levelValue >= getLevel());
307     }
308
309     /**
310      * Log a method entry.
311      * <p>
312      * This is a convenience method that can be used to log entry
313      * to a method. A LogRecord with message "ENTRY", log level
314      * FINER, and the given sourceMethod and sourceClass is logged.
315      * <p>
316      * @param sourceClass name of class that issued the logging request
317      * @param sourceMethod name of method that is being entered
318      */

319     public void entering (String JavaDoc sourceClass, String JavaDoc sourceMethod)
320     {
321         entering(sourceClass, sourceMethod, (Object JavaDoc[])null);
322     }
323
324     /**
325      * Log a method entry, with one parameter.
326      * <p>
327      * This is a convenience method that can be used to log entry
328      * to a method. A LogRecord with message "ENTRY {0}", log level
329      * FINER, and the given sourceMethod, sourceClass, and parameter
330      * is logged.
331      * <p>
332      * @param sourceClass name of class that issued the logging request
333      * @param sourceMethod name of method that is being entered
334      * @param param1 parameter to the method being entered
335      */

336     public void entering (String JavaDoc sourceClass, String JavaDoc sourceMethod,
337         Object JavaDoc param1)
338     {
339         if (isLoggable(FINER))
340             entering(sourceClass, sourceMethod, new Object JavaDoc[]{param1});
341     }
342
343     /**
344      * Log a method entry, with an array of parameters.
345      * <p>
346      * This is a convenience method that can be used to log entry
347      * to a method. A LogRecord with message "ENTRY" (followed by a
348      * format {N} indicator for each entry in the parameter array),
349      * log level FINER, and the given sourceMethod, sourceClass, and
350      * parameters is logged.
351      * <p>
352      * @param sourceClass name of class that issued the logging request
353      * @param sourceMethod name of method that is being entered
354      * @param params array of parameters to the method being entered
355      */

356     public void entering (String JavaDoc sourceClass, String JavaDoc sourceMethod,
357         Object JavaDoc params[])
358     {
359         if (isLoggable(FINER))
360         {
361             MessageFormat JavaDoc messageFormat = null;
362             String JavaDoc messageKey = null;
363             String JavaDoc[] args = null;
364
365             if ((params != null) && (params.length > 0))
366             {
367                 messageKey = "entering_method_params"; // NOI18N
368
args = new String JavaDoc[]{sourceClass, sourceMethod,
369                     StringHelper.arrayToSeparatedList(Arrays.asList(params))};
370             }
371             else
372             {
373                 messageKey = "entering_method"; // NOI18N
374
args = new String JavaDoc[]{sourceClass, sourceMethod};
375             }
376
377             messageFormat = new MessageFormat JavaDoc(
378                 getMessages().getString(messageKey));
379             finer(messageFormat.format(args));
380         }
381     }
382
383     /**
384      * Log a method return.
385      * <p>
386      * This is a convenience method that can be used to log returning
387      * from a method. A LogRecord with message "RETURN", log level
388      * FINER, and the given sourceMethod and sourceClass is logged.
389      * <p>
390      * @param sourceClass name of class that issued the logging request
391      * @param sourceMethod name of the method
392      */

393     public void exiting (String JavaDoc sourceClass, String JavaDoc sourceMethod)
394     {
395         exiting(sourceClass, sourceMethod, null);
396     }
397
398     /**
399      * Log a method return, with result object.
400      * <p>
401      * This is a convenience method that can be used to log returning
402      * from a method. A LogRecord with message "RETURN {0}", log level
403      * FINER, and the gives sourceMethod, sourceClass, and result
404      * object is logged.
405      * <p>
406      * @param sourceClass name of class that issued the logging request
407      * @param sourceMethod name of the method
408      * @param result Object that is being returned
409      */

410     public void exiting (String JavaDoc sourceClass, String JavaDoc sourceMethod, Object JavaDoc result)
411     {
412         if (isLoggable(FINER))
413         {
414             MessageFormat JavaDoc messageFormat = null;
415             String JavaDoc messageKey = null;
416             Object JavaDoc[] args = null;
417
418             if (result != null)
419             {
420                 messageKey = "exiting_method_return"; // NOI18N
421
args = new Object JavaDoc[]{sourceClass, sourceMethod, result};
422             }
423             else
424             {
425                 messageKey = "exiting_method"; // NOI18N
426
args = new Object JavaDoc[]{sourceClass, sourceMethod};
427             }
428
429             messageFormat = new MessageFormat JavaDoc(
430                 getMessages().getString(messageKey));
431             finer(messageFormat.format(args));
432         }
433     }
434
435     /**
436      * Log throwing an exception.
437      * <p>
438      * This is a convenience method to log that a method is
439      * terminating by throwing an exception. The logging is done
440      * using the FINER level.
441      * <p>
442      * If the logger is currently enabled for the given message
443      * level then the given arguments are stored in a LogRecord
444      * which is forwarded to all registered output handlers. The
445      * LogRecord's message is set to "THROW".
446      * <p>
447      * Note that the thrown argument is stored in the LogRecord thrown
448      * property, rather than the LogRecord parameters property. Thus is it
449      * processed specially by output Formatters and is not treated
450      * as a formatting parameter to the LogRecord message property.
451      * <p>
452      * @param sourceClass name of class that issued the logging request
453      * @param sourceMethod name of the method.
454      * @param thrown The Throwable that is being thrown.
455      */

456     public void throwing (String JavaDoc sourceClass, String JavaDoc sourceMethod,
457         Throwable JavaDoc thrown)
458     {
459         if (isLoggable(FINER))
460         {
461             MessageFormat JavaDoc messageFormat = new MessageFormat JavaDoc(
462                 getMessages().getString("throwing_method"));
463
464             log(FINER, messageFormat.format(
465                 new String JavaDoc[]{sourceClass, sourceMethod}), thrown);
466         }
467     }
468
469     /**
470      * Log a SEVERE message.
471      * <p>
472      * If the logger is currently enabled for the SEVERE message
473      * level then the given message is forwarded to all the
474      * registered output Handler objects.
475      * <p>
476      * @param msg The string message (or a key in the message catalog)
477      */

478     public void severe (String JavaDoc msg) { log(SEVERE, msg); }
479
480     /**
481      * Log a WARNING message.
482      * <p>
483      * If the logger is currently enabled for the WARNING message
484      * level then the given message is forwarded to all the
485      * registered output Handler objects.
486      * <p>
487      * @param msg The string message (or a key in the message catalog)
488      */

489     public void warning (String JavaDoc msg) { log(WARNING, msg); }
490
491     /**
492      * Log an INFO message.
493      * <p>
494      * If the logger is currently enabled for the INFO message
495      * level then the given message is forwarded to all the
496      * registered output Handler objects.
497      * <p>
498      * @param msg The string message (or a key in the message catalog)
499      */

500     public void info (String JavaDoc msg) { log(INFO, msg); }
501
502     /**
503      * Log a CONFIG message.
504      * <p>
505      * If the logger is currently enabled for the CONFIG message
506      * level then the given message is forwarded to all the
507      * registered output Handler objects.
508      * <p>
509      * @param msg The string message (or a key in the message catalog)
510      */

511     public void config (String JavaDoc msg) { log(CONFIG, msg); }
512
513     /**
514      * Log a message.
515      * <p>
516      * If the logger is currently enabled for the message
517      * level then the given message is forwarded to all the
518      * registered output Handler objects.
519      * <p>
520      * @param level The level for this message
521      * @param msg The string message (or a key in the message catalog)
522      */

523     public void log (int level, String JavaDoc msg)
524     {
525         if (isLoggable(level))
526             logInternal(level, getMessage(msg));
527     }
528
529     /**
530      * Log a message.
531      * <p>
532      * If the logger is currently enabled for the message
533      * level then the given message is forwarded to all the
534      * registered output Handler objects.
535      * <p>
536      * @param level The level for this message
537      * @param msg The string message (or a key in the message catalog)
538      * @param o1 A parameter to be inserted into the message
539      */

540     public void log (int level, String JavaDoc msg, Object JavaDoc o1)
541     {
542         if (isLoggable(level))
543             log(level, msg, new Object JavaDoc[]{o1});
544     }
545
546     /**
547      * Log a message.
548      * <p>
549      * If the logger is currently enabled for the message
550      * level then the given message is forwarded to all the
551      * registered output Handler objects.
552      * <p>
553      * @param level The level for this message
554      * @param msg The string message (or a key in the message catalog)
555      * @param o Objects to be inserted into the message
556      */

557     public void log (int level, String JavaDoc msg, Object JavaDoc[] o)
558     {
559         if (isLoggable(level))
560         {
561             int count = ((o == null) ? 0 : o.length);
562             String JavaDoc formattedMessage = msg;
563
564             if (count > 0)
565             {
566                 MessageFormat JavaDoc messageFormat =
567                     new MessageFormat JavaDoc(getBundle().getString(msg));
568
569                 if (messageFormat != null)
570                     formattedMessage = messageFormat.format(o);
571             }
572             else
573                 formattedMessage = getMessage(msg);
574
575             logInternal(level, formattedMessage);
576         }
577     }
578
579     /**
580      * Log a message.
581      * <p>
582      * If the logger is currently enabled for the message
583      * level then the given message is forwarded to all the
584      * registered output Handler objects.
585      * <p>
586      * @param level The level for this message
587      * @param msg The string message (or a key in the message catalog)
588      * @param o1 A parameter to be inserted into the message
589      * @param o2 A parameter to be inserted into the message
590      */

591     public void log (int level, String JavaDoc msg, Object JavaDoc o1, Object JavaDoc o2)
592     {
593         if (isLoggable(level))
594             log(level, msg, new Object JavaDoc[]{o1, o2});
595     }
596     
597     /**
598      * Log a message.
599      * <p>
600      * If the logger is currently enabled for the message
601      * level then the given message is forwarded to all the
602      * registered output Handler objects.
603      * <p>
604      * @param level The level for this message
605      * @param msg The string message (or a key in the message catalog)
606      * @param o1 A parameter to be inserted into the message
607      * @param o2 A parameter to be inserted into the message
608      * @param o3 A parameter to be inserted into the message
609      */

610     public void log (int level, String JavaDoc msg, Object JavaDoc o1, Object JavaDoc o2, Object JavaDoc o3)
611     {
612         if (isLoggable(level))
613             log(level, msg, new Object JavaDoc[]{o1, o2, o3});
614     }
615
616     /**
617      * Log a message.
618      * <p>
619      * If the logger is currently enabled for the message
620      * level then the given message, and the exception dump,
621      * is forwarded to all the
622      * registered output Handler objects.
623      * <p>
624      * @param level The level for this message
625      * @param msg The string message (or a key in the message catalog)
626      * @param thrown The exception to log
627      */

628     abstract public void log (int level, String JavaDoc msg, Throwable JavaDoc thrown);
629
630     /**
631      * Log a message.
632      * <p>
633      * If the logger is currently enabled for the message
634      * level then the given message is forwarded to all the
635      * registered output Handler objects.
636      * <p>
637      * @param msg The string message (or a key in the message catalog)
638      */

639     public void fine (String JavaDoc msg) { log(FINE, msg); }
640
641     /**
642      * Log a FINE message.
643      * <p>
644      * If the logger is currently enabled for the FINE message
645      * level then the given message is forwarded to all the
646      * registered output Handler objects.
647      * <p>
648      * @param msg The string message (or a key in the message catalog)
649      * @param o1 A parameter to be inserted into the message
650      */

651     public void fine (String JavaDoc msg, Object JavaDoc o1) { log(FINE, msg, o1); }
652
653     /**
654      * Log a FINE message.
655      * <p>
656      * If the logger is currently enabled for the FINE message
657      * level then the given message is forwarded to all the
658      * registered output Handler objects.
659      * <p>
660      * @param msg The string message (or a key in the message catalog)
661      * @param o Objects to be inserted into the message
662      */

663     public void fine (String JavaDoc msg, Object JavaDoc[] o) { log(FINE, msg, o); }
664
665     /**
666      * Log a FINE message.
667      * <p>
668      * If the logger is currently enabled for the FINE message
669      * level then the given message is forwarded to all the
670      * registered output Handler objects.
671      * <p>
672      * @param msg The string message (or a key in the message catalog)
673      * @param o1 A parameter to be inserted into the message
674      * @param o2 A parameter to be inserted into the message
675      */

676     public void fine (String JavaDoc msg, Object JavaDoc o1, Object JavaDoc o2)
677     {
678         log(FINE, msg, o1, o2);
679     }
680
681     /**
682      * Log a FINE message.
683      * <p>
684      * If the logger is currently enabled for the FINE message
685      * level then the given message is forwarded to all the
686      * registered output Handler objects.
687      * <p>
688      * @param msg The string message (or a key in the message catalog)
689      * @param o1 A parameter to be inserted into the message
690      * @param o2 A parameter to be inserted into the message
691      * @param o3 A parameter to be inserted into the message
692      */

693     public void fine (String JavaDoc msg, Object JavaDoc o1, Object JavaDoc o2, Object JavaDoc o3)
694     {
695         log(FINE, msg, o1, o2, o3);
696     }
697     
698     /**
699      * Log a FINER message.
700      * <p>
701      * If the logger is currently enabled for the FINER message
702      * level then the given message is forwarded to all the
703      * registered output Handler objects.
704      * <p>
705      * @param msg The string message (or a key in the message catalog)
706      */

707     public void finer (String JavaDoc msg) { log(FINER, msg); }
708
709     /**
710      * Log a FINER message.
711      * <p>
712      * If the logger is currently enabled for the FINER message
713      * level then the given message is forwarded to all the
714      * registered output Handler objects.
715      * <p>
716      * @param msg The string message (or a key in the message catalog)
717      * @param o Objects to be inserted into the message
718      */

719     public void finer (String JavaDoc msg, Object JavaDoc[] o) { log(FINER, msg, o); }
720
721     /**
722      * Log a FINER message.
723      * <p>
724      * If the logger is currently enabled for the FINER message
725      * level then the given message is forwarded to all the
726      * registered output Handler objects.
727      * <p>
728      * @param msg The string message (or a key in the message catalog)
729      * @param o1 A parameter to be inserted into the message
730      */

731     public void finer (String JavaDoc msg, Object JavaDoc o1) { log(FINER, msg, o1); }
732
733     /**
734      * Log a FINER message.
735      * <p>
736      * If the logger is currently enabled for the FINER message
737      * level then the given message is forwarded to all the
738      * registered output Handler objects.
739      * <p>
740      * @param msg The string message (or a key in the message catalog)
741      * @param o1 A parameter to be inserted into the message
742      * @param o2 A parameter to be inserted into the message
743      */

744     public void finer (String JavaDoc msg, Object JavaDoc o1, Object JavaDoc o2)
745     {
746         log(FINER, msg, o1, o2);
747     }
748     
749     /**
750      * Log a FINER message.
751      * <p>
752      * If the logger is currently enabled for the FINER message
753      * level then the given message is forwarded to all the
754      * registered output Handler objects.
755      * <p>
756      * @param msg The string message (or a key in the message catalog)
757      * @param o1 A parameter to be inserted into the message
758      * @param o2 A parameter to be inserted into the message
759      * @param o3 A parameter to be inserted into the message
760      */

761     public void finer (String JavaDoc msg, Object JavaDoc o1, Object JavaDoc o2, Object JavaDoc o3)
762     {
763         log(FINER, msg, o1, o2, o3);
764     }
765
766     /**
767      * Log a FINEST message.
768      * <p>
769      * If the logger is currently enabled for the FINEST message
770      * level then the given message is forwarded to all the
771      * registered output Handler objects.
772      * <p>
773      * @param msg The string message (or a key in the message catalog)
774      */

775     public void finest (String JavaDoc msg) { log(FINEST, msg); }
776
777     /**
778      * Log a FINEST message.
779      * <p>
780      * If the logger is currently enabled for the FINEST message
781      * level then the given message is forwarded to all the
782      * registered output Handler objects.
783      * <p>
784      * @param msg The string message (or a key in the message catalog)
785      * @param o Objects to be inserted into the message
786      */

787     public void finest (String JavaDoc msg, Object JavaDoc[] o) { log(FINEST, msg, o); }
788
789     /**
790      * Log a FINEST message.
791      * <p>
792      * If the logger is currently enabled for the FINEST message
793      * level then the given message is forwarded to all the
794      * registered output Handler objects.
795      * <p>
796      * @param msg The string message (or a key in the message catalog)
797      * @param o1 A parameter to be inserted into the message
798      */

799     public void finest (String JavaDoc msg, Object JavaDoc o1) { log(FINEST, msg, o1); }
800
801     /**
802      * Log a FINEST message.
803      * <p>
804      * If the logger is currently enabled for the FINEST message
805      * level then the given message is forwarded to all the
806      * registered output Handler objects.
807      * <p>
808      * @param msg The string message (or a key in the message catalog)
809      * @param o1 A parameter to be inserted into the message
810      * @param o2 A parameter to be inserted into the message
811      */

812     public void finest (String JavaDoc msg, Object JavaDoc o1, Object JavaDoc o2)
813     {
814         log(FINEST, msg, o1, o2);
815     }
816     
817     /**
818      * Log a FINEST message.
819      * <p>
820      * If the logger is currently enabled for the FINEST message
821      * level then the given message is forwarded to all the
822      * registered output Handler objects.
823      * <p>
824      * @param msg The string message (or a key in the message catalog)
825      * @param o1 A parameter to be inserted into the message
826      * @param o2 A parameter to be inserted into the message
827      * @param o3 A parameter to be inserted into the message
828      */

829     public void finest (String JavaDoc msg, Object JavaDoc o1, Object JavaDoc o2, Object JavaDoc o3)
830     {
831         log(FINEST, msg, o1, o2, o3);
832     }
833
834     /**
835      * Get the name for this logger.
836      * @return logger name. Will be null for anonymous Loggers.
837      */

838     public String JavaDoc getName () { return _loggerName; }
839
840     /** Prepare a printable version of this instance.
841      * @return the String representation of this object
842      */

843     public String JavaDoc toString ()
844     {
845         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(getClass().getName());
846
847         buffer.append(": "); //NOI18N
848
buffer.append(" name: "); //NOI18N
849
buffer.append(getName());
850         buffer.append(", logging level: "); //NOI18N
851
buffer.append(toString(getLevel()));
852
853         return buffer.toString();
854     }
855
856     /**
857      * This method returns a string from the bundle file if possible,
858      * treating the message argument as the key. If no such key is found
859      * in the bundle, the message itself is returned.
860      *
861      * @return a message either used as itself or searched in the bundle file.
862      * @param message the message which is used as a key to search the bundle
863      */

864     protected String JavaDoc getMessage (String JavaDoc message)
865     {
866         try
867         {
868             return getBundle().getString(message);
869         }
870         catch (MissingResourceException e)
871         {
872             return message;
873         }
874
875     }
876
877     /**
878      * This method returns a string with a formatted prefix which
879      * depends on the level.
880      *
881      * @return a formatted string with a level prefix.
882      * @param level the level to print
883      * @param message the message to print
884      * @see AbstractLogger#toString
885      */

886     protected String JavaDoc getMessageWithPrefix (int level, String JavaDoc message)
887     {
888         MessageFormat JavaDoc messageFormat = new MessageFormat JavaDoc(
889             getMessages().getString("logging_prefix")); // NOI18N
890

891         return messageFormat.format(
892             new String JavaDoc[]{toString(level), message});
893     }
894     
895     /**
896      * This method does the actual logging. It is expected that if a
897      * check for isLoggable is desired for performance reasons, it has
898      * already been done, as it should not be done here.
899      * @param level the level to print
900      * @param message the message to print
901      */

902     abstract protected void logInternal (int level, String JavaDoc message);
903 }
904
Popular Tags