KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > logging > AbstractSessionLog


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
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
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 in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.logging;
23
24 import java.util.*;
25 import java.text.*;
26 import java.io.*;
27 import oracle.toplink.essentials.sessions.Session;
28 import oracle.toplink.essentials.internal.databaseaccess.Accessor;
29 import oracle.toplink.essentials.internal.localization.*;
30 import oracle.toplink.essentials.exceptions.*;
31 import oracle.toplink.essentials.internal.sessions.AbstractSession;
32
33 /**
34  * Represents the abstract log that implements all the generic logging functions.
35  * It contains a singleton SessionLog that logs messages from outside any TopLink session.
36  * The singleton SessionLog can also be passed to a TopLink session when messages
37  * are logged through that session. When JDK1.4 is used, a singleton JavaLog is created.
38  * Otherwise a singleton DefaultSessionLog is created.
39  *
40  * @see SessionLog
41  * @see SessionLogEntry
42  * @see DefaultSessionLog
43  * @see JavaLog
44  */

45 public abstract class AbstractSessionLog implements SessionLog, java.lang.Cloneable JavaDoc {
46
47     /**
48      * Represents the log level
49      */

50     protected int level;
51
52     /**
53      * Represents the singleton SessionLog
54      */

55     protected static SessionLog defaultLog;
56
57     /**
58      * Represents the session that owns this SessionLog
59      */

60     protected Session session;
61
62     /**
63      * Represents the session type of the session that owns this SessionLog
64      */

65     protected String JavaDoc sessionType;
66
67     /**
68      * Caches the session hash code string of the session that owns this SessionLog
69      */

70     protected String JavaDoc sessionHashCode;
71
72     /**
73      * Represents prefix to logged severe
74      */

75     protected static String JavaDoc SEVERE_PREFIX = null;
76
77     /**
78      * Represents prefix to logged warning
79      */

80     protected static String JavaDoc WARNING_PREFIX = null;
81
82     /**
83      * Represents prefix to logged info
84      */

85     protected static String JavaDoc INFO_PREFIX = null;
86
87     /**
88      * Represents prefix to logged config
89      */

90     protected static String JavaDoc CONFIG_PREFIX = null;
91
92     /**
93      * Represents prefix to logged fine
94      */

95     protected static String JavaDoc FINE_PREFIX = null;
96
97     /**
98      * Represents prefix to logged finer
99      */

100     protected static String JavaDoc FINER_PREFIX = null;
101
102     /**
103      * Represents prefix to logged finest
104      */

105     protected static String JavaDoc FINEST_PREFIX = null;
106
107     /**
108      * Cached TopLink prefix string.
109      */

110     protected static String JavaDoc TOPLINK_PREFIX = null;
111
112     /**
113      * Connection string
114      */

115     protected static String JavaDoc CONNECTION_STRING = "Connection";
116
117     /**
118      * Thread string
119      */

120     protected static String JavaDoc THREAD_STRING = "Thread";
121
122     /**
123      * Represents the writer that will receive the formatted log entries
124      */

125     protected Writer writer;
126     
127     /**
128      * Format use to print the current date/time.
129      */

130     protected DateFormat dateFormat;
131     
132     /**
133      * Allows the printing of the stack to be explictitly disabled/enabled.
134      * CR #3870467.
135      * null value is default behavoir of determining from log level.
136      */

137     protected Boolean JavaDoc shouldLogExceptionStackTrace;
138     
139     /**
140      * Allows the printing of the date to be explictitly disabled/enabled.
141      * CR #3870467.
142      * null value is default behavoir of determining from log level.
143      */

144     protected Boolean JavaDoc shouldPrintDate;
145     
146     /**
147      * Allows the printing of the thread to be explictitly disabled/enabled.
148      * CR #3870467.
149      * null value is default behavoir of determining from log level.
150      */

151     protected Boolean JavaDoc shouldPrintThread;
152         
153     /**
154      * Allows the printing of the session to be explictitly disabled/enabled.
155      * CR #3870467.
156      * null value is default behavoir of determining from log level.
157      */

158     protected Boolean JavaDoc shouldPrintSession;
159
160     /**
161      * Allows the printing of the connection to be explictitly disabled/enabled.
162      * CR #4157545.
163      * null value is default behavoir of determining from log level.
164      */

165     protected Boolean JavaDoc shouldPrintConnection;
166
167     /**
168      * PUBLIC:
169      * Create a new AbstractSessionLog
170      */

171     public AbstractSessionLog() {
172         this.writer = new PrintWriter(System.out);
173     }
174
175     /**
176      * PUBLIC:
177      * <p>
178      * Return the log level. It is used when session is not available.
179      * </p><p>
180      *
181      * @return the log level
182      * </p>
183      */

184     public int getLevel() {
185         return getLevel(null);
186     }
187
188     /**
189      * PUBLIC:
190      * <p>
191      * Return the log level. Category is only needed in JavaLog
192      * to extract name space for the Logger which the log level belongs to.
193      * </p><p>
194      *
195      * @return the log level
196      * </p><p>
197      * @param category the string representation of a TopLink category, e.g. "sql", "transaction" ...
198      * </p>
199      */

200     public int getLevel(String JavaDoc category) {
201         return level;
202     }
203
204     /**
205      * PUBLIC:
206      * <p>
207      * Set the log level. It is used when session is not available.
208      * </p><p>
209      *
210      * @param level the new log level
211      * </p>
212      */

213     public void setLevel(int level) {
214         setLevel(level, null);
215     }
216
217     /**
218      * PUBLIC:
219      * <p>
220      * Set the log level. Category is only needed in JavaLog
221      * to extract name space for the Logger which the log level belongs to.
222      * </p><p>
223      *
224      * @param level the new log level
225      * @param category the string representation of a TopLink category, e.g. "sql", "transaction" ...
226      * </p>
227      */

228     public void setLevel(int level, String JavaDoc category) {
229         this.level = level;
230     }
231
232     /**
233      * PUBLIC:
234      * <p>
235      * Check if a message of the given level would actually be logged.
236      * It is used when session is not available.
237      * </p><p>
238      *
239      * @return true if the given message level will be logged
240      * </p><p>
241      * @param level the log request level
242      * </p>
243      */

244     public boolean shouldLog(int level) {
245         return shouldLog(level, null);
246     }
247
248     /**
249      * PUBLIC:
250      * <p>
251      * Check if a message of the given level would actually be logged. Category
252      * is only needed in JavaLog to extract name space for the Logger which the log
253      * level belongs to. !isOff() is checked to screen out the possibility when both
254      * log level and log request level are set to OFF.
255      * </p><p>
256      *
257      * @return true if the given message level will be logged
258      * </p><p>
259      * @param level the log request level
260      * @param category the string representation of a TopLink category, e.g. "sql", "transaction" ...* </p>
261      * </p>
262      */

263     public boolean shouldLog(int level, String JavaDoc category) {
264         return (this.level <= level) && !isOff();
265     }
266
267     /**
268      * PUBLIC:
269      * <p>
270      * Return the singleton SessionLog. If the singleton SessionLog does not exist,
271      * a new one is created based on the version of JDK being used from the Version class.
272      * </p><p>
273      *
274      * @return the singleton SessionLog
275      * </p>
276      */

277     public static SessionLog getLog() {
278         if (defaultLog == null) {
279             defaultLog = new DefaultSessionLog();
280         }
281         return defaultLog;
282     }
283
284     /**
285      * PUBLIC:
286      * <p>
287      * Set the singleton SessionLog.
288      * </p>
289      *
290      * @param sessionLog a SessionLog
291      * </p>
292      */

293     public static void setLog(SessionLog sessionLog) {
294         defaultLog = sessionLog;
295         defaultLog.setSession(null);
296     }
297
298     /**
299      * PUBLIC:
300      * <p>
301      * Get the session.
302      * </p>
303      *
304      * @return session
305      * </p>
306      */

307     public Session getSession() {
308         return this.session;
309     }
310
311     /**
312      * PUBLIC:
313      * <p>
314      * Set the session.
315      * </p>
316      *
317      * @param session a Session
318      * </p>
319      */

320     public void setSession(Session session) {
321         if (this.session == null) {
322             this.session = session;
323             buildSessionType();
324             buildSessionHashCode();
325         }
326     }
327
328     /**
329      * PUBLIC:
330      * <p>
331      * Log a message that does not need to be translated. This method is intended for
332      * external use when logging messages are wanted within the TopLink output.
333      * </p><p>
334      *
335      * @param level the log request level value
336      * </p><p>
337      * @param message the string message
338      * </p>
339      */

340     public void log(int level, String JavaDoc message) {
341         if (!shouldLog(level)) {
342             return;
343         }
344         //Bug#4566524 Pass in false for external use
345
log(level, message, (Object JavaDoc[])null, false);
346     }
347
348     /**
349      * INTERNAL:
350      * <p>
351      * Log a message with one parameter that needs to be translated.
352      * </p><p>
353      *
354      * @param level the log request level value
355      * </p><p>
356      * @param message the string message
357      * </p><p>
358      * @param param a parameter of the message
359      * </p>
360      */

361     public void log(int level, String JavaDoc message, Object JavaDoc param) {
362         if (!shouldLog(level)) {
363             return;
364         }
365         log(level, message, new Object JavaDoc[] { param });
366     }
367
368     /**
369      * INTERNAL:
370      * <p>
371      * Log a message with two parameters that needs to be translated.
372      * </p><p>
373      *
374      * @param level the log request level value
375      * </p><p>
376      * @param message the string message
377      * </p><p>
378      * @param param1 a parameter of the message
379      * </p><p>
380      * @param param2 second parameter of the message
381      * </p>
382      */

383     public void log(int level, String JavaDoc message, Object JavaDoc param1, Object JavaDoc param2) {
384         if (!shouldLog(level)) {
385             return;
386         }
387         log(level, message, new Object JavaDoc[] { param1, param2 });
388     }
389
390     /**
391      * INTERNAL:
392      * <p>
393      * Log a message with three parameters that needs to be translated.
394      * </p><p>
395      *
396      * @param level the log request level value
397      * </p><p>
398      * @param message the string message
399      * </p><p>
400      * @param param1 a parameter of the message
401      * </p><p>
402      * @param param2 second parameter of the message
403      * </p><p>
404      * @param param3 third parameter of the message
405      * </p>
406      */

407     public void log(int level, String JavaDoc message, Object JavaDoc param1, Object JavaDoc param2, Object JavaDoc param3) {
408         if (!shouldLog(level)) {
409             return;
410         }
411         log(level, message, new Object JavaDoc[] { param1, param2, param3 });
412     }
413
414     /**
415      * INTERNAL:
416      * <p>
417      * Log a message with an array of parameters that needs to be translated.
418      * </p><p>
419      *
420      * @param level the log request level value
421      * </p><p>
422      * @param message the string message
423      * </p><p>
424      * @param params array of parameters to the message
425      * </p>
426      */

427     public void log(int level, String JavaDoc message, Object JavaDoc[] params) {
428         log(level, message, params, true);
429     }
430
431     /**
432      * INTERNAL:
433      * <p>
434      * Log a message. shouldTranslate determines if the message needs to be translated.
435      * </p><p>
436      *
437      * @param level the log request level
438      * </p><p>
439      * @param message the string message
440      * </p><p>
441      * @param params array of parameters to the message
442      * </p><p>
443      * @param shouldTranslate true if the message needs to be translated
444      * </p>
445      */

446     public void log(int level, String JavaDoc message, Object JavaDoc[] params, boolean shouldTranslate) {
447         if (!shouldLog(level)) {
448             return;
449         }
450         log(new SessionLogEntry(level, null, message, params, null, shouldTranslate));
451     }
452
453     /**
454      * PUBLIC:
455      * <p>
456      * Log a SessionLogEntry
457      * </p><p>
458      *
459      * @param entry SessionLogEntry that holds all the information for a TopLink logging event
460      * </p>
461      */

462     public abstract void log(SessionLogEntry sessionLogEntry);
463     
464     /**
465      * By default the session (and its connection is available) are printed,
466      * this can be turned off.
467      */

468     public boolean shouldPrintSession() {
469         return (shouldPrintSession == null) || shouldPrintSession.booleanValue();
470     }
471
472     /**
473      * By default the session (and its connection is available) are printed,
474      * this can be turned off.
475      */

476     public void setShouldPrintSession(boolean shouldPrintSession) {
477         if (shouldPrintSession) {
478             this.shouldPrintSession = Boolean.TRUE;
479         } else {
480             this.shouldPrintSession = Boolean.FALSE;
481         }
482     }
483
484     /**
485      * By default the connection is printed, this can be turned off.
486      */

487     public boolean shouldPrintConnection() {
488         return (shouldPrintConnection == null) || shouldPrintConnection.booleanValue();
489     }
490
491     /**
492      * By default the connection is printed, this can be turned off.
493      */

494     public void setShouldPrintConnection(boolean shouldPrintConnection) {
495         if (shouldPrintConnection) {
496             this.shouldPrintConnection = Boolean.TRUE;
497         } else {
498             this.shouldPrintConnection = Boolean.FALSE;
499         }
500     }
501
502     /**
503      * By default the stack is logged for FINER or less (finest).
504      * The logging of the stack can also be explicitly turned on or off.
505      */

506     public boolean shouldLogExceptionStackTrace() {
507         if (shouldLogExceptionStackTrace == null) {
508             return getLevel() <= FINER;
509         } else {
510             return shouldLogExceptionStackTrace.booleanValue();
511         }
512     }
513
514     /**
515      * By default the stack is logged for FINER or less (finest).
516      * The logging of the stack can also be explicitly turned on or off.
517      */

518     public void setShouldLogExceptionStackTrace(boolean shouldLogExceptionStackTrace) {
519         if (shouldLogExceptionStackTrace) {
520             this.shouldLogExceptionStackTrace = Boolean.TRUE;
521         } else {
522             this.shouldLogExceptionStackTrace = Boolean.FALSE;
523         }
524     }
525
526     /**
527      * By default the date is always printed, but can be turned off.
528      */

529     public boolean shouldPrintDate() {
530         return (shouldPrintDate == null) || (shouldPrintDate.booleanValue());
531     }
532
533     /**
534      * By default the date is always printed, but can be turned off.
535      */

536     public void setShouldPrintDate(boolean shouldPrintDate) {
537         if (shouldPrintDate) {
538             this.shouldPrintDate = Boolean.TRUE;
539         } else {
540             this.shouldPrintDate = Boolean.FALSE;
541         }
542     }
543
544     /**
545      * By default the thread is logged for FINE or less (finer,etc.).
546      * The logging of the thread can also be explicitly turned on or off.
547      */

548     public boolean shouldPrintThread() {
549         if (shouldPrintThread == null) {
550             return getLevel() <= FINE;
551         } else {
552             return shouldPrintThread.booleanValue();
553         }
554     }
555
556     /**
557      * By default the thread is logged for FINE or less (finer,etc.).
558      * The logging of the thread can also be explicitly turned on or off.
559      */

560     public void setShouldPrintThread(boolean shouldPrintThread) {
561         if (shouldPrintThread) {
562             this.shouldPrintThread = Boolean.TRUE;
563         } else {
564             this.shouldPrintThread = Boolean.FALSE;
565         }
566     }
567
568     /**
569      * PUBLIC:
570      * <p>
571      * Return the writer that will receive the formatted log entries.
572      * </p><p>
573      *
574      * @return the log writer
575      * </p>
576      */

577     public Writer getWriter() {
578         return writer;
579     }
580
581     /**
582      * PUBLIC:
583      * <p>
584      * Set the writer that will receive the formatted log entries.
585      * </p><p>
586      *
587      * @param writer the log writer
588      * </p>
589      */

590     public void setWriter(Writer writer) {
591         this.writer = writer;
592     }
593
594     /**
595      * Build and return a date format.
596      * The default is a format that is sortable and easily parsed.
597      * @return the date format
598      */

599     protected DateFormat buildDefaultDateFormat() {
600         return new SimpleDateFormat("yyyy.MM.dd hh:mm:ss.SSS");
601     }
602
603     /**
604      * PUBLIC:
605      * Return the date format to be used when printing a log entry date.
606      * @return the date format
607      */

608     public DateFormat getDateFormat() {
609         if (dateFormat == null) {
610             dateFormat = this.buildDefaultDateFormat();
611         }
612         return dateFormat;
613     }
614
615     /**
616      * Return the specified date and/or time information in string.
617      * The format will be determined by the date format settings.
618      */

619     protected String JavaDoc getDateString(Date date) {
620         return this.getDateFormat().format(date);
621     }
622
623     /**
624      * Return the supplement detail information including date, session, thread and connection.
625      */

626     protected String JavaDoc getSupplementDetailString(SessionLogEntry entry) {
627         StringWriter writer = new StringWriter();
628
629         if (shouldPrintDate()) {
630             writer.write(getDateString(entry.getDate()));
631             writer.write("--");
632         }
633         if (shouldPrintSession() && (entry.getSession() != null)) {
634             writer.write(this.getSessionString(entry.getSession()));
635             writer.write("--");
636         }
637         if (shouldPrintConnection() && (entry.getConnection() != null)) {
638             writer.write(this.getConnectionString(entry.getConnection()));
639             writer.write("--");
640         }
641         if (shouldPrintThread()) {
642             writer.write(this.getThreadString(entry.getThread()));
643             writer.write("--");
644         }
645         return writer.toString();
646     }
647
648     /**
649      * Return the current session including the type and id.
650      */

651     protected String JavaDoc getSessionString(Session session) {
652         // For bug 3422759 the session to log against should be the one in the
653
// event, not the static one in the SessionLog, for there are many
654
// sessions but only one SessionLog.
655
if (session != null) {
656             return ((AbstractSession)session).getLogSessionString();
657         } else {
658             return getSessionString();
659         }
660     }
661
662     /**
663      * Return the current session type.
664      */

665     protected void buildSessionType() {
666         if (session != null) {
667             sessionType = ((AbstractSession)session).getSessionTypeString();
668         } else {
669             sessionType = null;
670         }
671     }
672
673     /**
674      * Return the current session hash code.
675      */

676     protected void buildSessionHashCode() {
677         if (session != null) {
678             sessionHashCode = String.valueOf(System.identityHashCode(session));
679         } else {
680             sessionHashCode = null;
681         }
682     }
683
684     /**
685      * Return the current session including the type and id.
686      */

687     protected String JavaDoc getSessionString() {
688         return sessionType + "(" + sessionHashCode + ")";
689     }
690
691     /**
692      * Return the specified connection information.
693      */

694     protected String JavaDoc getConnectionString(Accessor connection) {
695         // Bug 3630182 - if possible, print the actual connection's hashcode instead of just the accessor
696
if (connection.getDatasourceConnection() == null){
697             return CONNECTION_STRING + "(" + String.valueOf(System.identityHashCode(connection)) + ")";
698         } else {
699              return CONNECTION_STRING + "(" + String.valueOf(System.identityHashCode(connection.getDatasourceConnection())) + ")";
700         }
701     }
702
703     /**
704      * Return the specified thread information.
705      */

706     protected String JavaDoc getThreadString(Thread JavaDoc thread) {
707         return THREAD_STRING + "(" + String.valueOf(thread) + ")";
708     }
709
710     /**
711      * Print the prefix string representing TopLink logging
712      */

713
714     //Bug3135111 Prefix strings are not translated until the first time they are used.
715
protected void printPrefixString(int level) {
716         try {
717             switch (level) {
718             case SEVERE:
719                 if (SEVERE_PREFIX == null) {
720                     SEVERE_PREFIX = LoggingLocalization.buildMessage("toplink_severe");
721                 }
722                 this.getWriter().write(SEVERE_PREFIX);
723                 break;
724             case WARNING:
725                 if (WARNING_PREFIX == null) {
726                     WARNING_PREFIX = LoggingLocalization.buildMessage("toplink_warning");
727                 }
728                 this.getWriter().write(WARNING_PREFIX);
729                 break;
730             case INFO:
731                 if (INFO_PREFIX == null) {
732                     INFO_PREFIX = LoggingLocalization.buildMessage("toplink_info");
733                 }
734                 this.getWriter().write(INFO_PREFIX);
735                 break;
736             case CONFIG:
737                 if (CONFIG_PREFIX == null) {
738                     CONFIG_PREFIX = LoggingLocalization.buildMessage("toplink_config");
739                 }
740                 this.getWriter().write(CONFIG_PREFIX);
741                 break;
742             case FINE:
743                 if (FINE_PREFIX == null) {
744                     FINE_PREFIX = LoggingLocalization.buildMessage("toplink_fine");
745                 }
746                 this.getWriter().write(FINE_PREFIX);
747                 break;
748             case FINER:
749                 if (FINER_PREFIX == null) {
750                     FINER_PREFIX = LoggingLocalization.buildMessage("toplink_finer");
751                 }
752                 this.getWriter().write(FINER_PREFIX);
753                 break;
754             case FINEST:
755                 if (FINEST_PREFIX == null) {
756                     FINEST_PREFIX = LoggingLocalization.buildMessage("toplink_finest");
757                 }
758                 this.getWriter().write(FINEST_PREFIX);
759                 break;
760             default:
761                 if (TOPLINK_PREFIX == null) {
762                     TOPLINK_PREFIX = LoggingLocalization.buildMessage("toplink");
763                 }
764                 this.getWriter().write(TOPLINK_PREFIX);
765             }
766         } catch (IOException exception) {
767             throw ValidationException.logIOError(exception);
768         }
769     }
770
771     /**
772      * PUBLIC:
773      * Set the date format to be used when
774      * printing a log entry date.
775      * @param dateFormat java.text.DateFormat
776      */

777     public void setDateFormat(DateFormat dateFormat) {
778         this.dateFormat = dateFormat;
779     }
780
781     /**
782      * Return the formatted message based on the information from the given SessionLogEntry.
783      * The message will either be translated and formatted or formatted only depending
784      * on if the shouldTranslate flag is set to true of false.
785      */

786     protected String JavaDoc formatMessage(SessionLogEntry entry) {
787         String JavaDoc message = entry.getMessage();
788         if (entry.shouldTranslate()) {
789             if (entry.getLevel() > FINE) {
790                 message = LoggingLocalization.buildMessage(message, entry.getParameters());
791             } else {
792                 message = TraceLocalization.buildMessage(message, entry.getParameters());
793             }
794         } else {
795             if (message.indexOf("{0") >= 0) {
796                 message = java.text.MessageFormat.format(message, entry.getParameters());
797             }
798         }
799         return message;
800     }
801
802     /**
803      * PUBLIC:
804      * <p>
805      * Log a throwable at FINER level.
806      * </p><p>
807      *
808      * @param throwable a Throwable
809      * </p>
810      */

811     public void throwing(Throwable JavaDoc throwable) {
812         if (shouldLog(FINER)) {
813             SessionLogEntry entry = new SessionLogEntry(null, throwable);
814             entry.setLevel(FINER);
815             log(entry);
816         }
817     }
818     
819     /**
820      * INTERNAL:
821      * Translate the string value of the log level to the constant value.
822      * If value is null or invalid use the default.
823      */

824     public static int translateStringToLoggingLevel(String JavaDoc loggingLevel){
825         if (loggingLevel == null){
826             return INFO;
827         } else if (loggingLevel.equals("OFF")){
828             return OFF;
829         } else if (loggingLevel.equals("SEVERE")){
830             return SEVERE;
831         } else if (loggingLevel.equals("WARNING")){
832             return WARNING;
833         } else if (loggingLevel.equals("INFO")){
834             return INFO;
835         } else if (loggingLevel.equals("CONFIG")){
836             return CONFIG;
837         } else if (loggingLevel.equals("FINE")){
838             return FINE;
839         } else if (loggingLevel.equals("FINER")){
840             return FINER;
841         } else if (loggingLevel.equals("FINEST")){
842             return FINEST;
843         } else if (loggingLevel.equals("ALL")){
844             return ALL;
845         }
846         return INFO;
847     }
848
849     /**
850      * INTERNAL:
851      * Translate the string value of the log level to the constant value.
852      * If value is null or invalid use the default.
853      */

854     public static String JavaDoc translateLoggingLevelToString(int loggingLevel){
855         if (loggingLevel == OFF){
856             return "OFF";
857         } else if (loggingLevel == SEVERE){
858             return "SEVERE";
859         } else if (loggingLevel == WARNING){
860             return "WARNING";
861         } else if (loggingLevel == INFO){
862             return "INFO";
863         } else if (loggingLevel == CONFIG){
864             return "CONFIG";
865         } else if (loggingLevel == FINE){
866             return "FINE";
867         } else if (loggingLevel == FINER){
868             return "FINER";
869         } else if (loggingLevel == FINEST){
870             return "FINEST";
871         } else if (loggingLevel == ALL){
872             return "ALL";
873         }
874         return "INFO";
875     }
876
877     /**
878      * PUBLIC:
879      * <p>
880      * This method is called when a severe level message needs to be logged.
881      * The message will be translated
882      * </p><p>
883      *
884      * @param message the message key
885      * </p>
886      */

887     public void severe(String JavaDoc message) {
888         log(SEVERE, message, (Object JavaDoc[])null);
889     }
890
891     /**
892      * PUBLIC:
893      * <p>
894      * This method is called when a warning level message needs to be logged.
895      * The message will be translated
896      * </p><p>
897      *
898      * @param message the message key
899      * </p>
900      */

901     public void warning(String JavaDoc message) {
902         log(WARNING, message, (Object JavaDoc[])null);
903     }
904
905     /**
906      * PUBLIC:
907      * <p>
908      * This method is called when a info level message needs to be logged.
909      * The message will be translated
910      * </p><p>
911      *
912      * @param message the message key
913      * </p>
914      */

915     public void info(String JavaDoc message) {
916         log(INFO, message, (Object JavaDoc[])null);
917     }
918
919     /**
920      * PUBLIC:
921      * <p>
922      * This method is called when a config level message needs to be logged.
923      * The message will be translated
924      * </p><p>
925      *
926      * @param message the message key
927      * </p>
928      */

929     public void config(String JavaDoc message) {
930         log(CONFIG, message, (Object JavaDoc[])null);
931     }
932
933     /**
934      * PUBLIC:
935      * <p>
936      * This method is called when a fine level message needs to be logged.
937      * The message will be translated
938      * </p><p>
939      *
940      * @param message the message key
941      * </p>
942      */

943     public void fine(String JavaDoc message) {
944         log(FINE, message, (Object JavaDoc[])null);
945     }
946
947     /**
948      * PUBLIC:
949      * <p>
950      * This method is called when a finer level message needs to be logged.
951      * The message will be translated
952      * </p><p>
953      *
954      * @param message the message key
955      * </p>
956      */

957     public void finer(String JavaDoc message) {
958         log(FINER, message, (Object JavaDoc[])null);
959     }
960
961     /**
962      * PUBLIC:
963      * <p>
964      * This method is called when a finest level message needs to be logged.
965      * The message will be translated
966      * </p><p>
967      *
968      * @param message the message key
969      * </p>
970      */

971     public void finest(String JavaDoc message) {
972         log(FINEST, message, (Object JavaDoc[])null);
973     }
974
975     /**
976      * PUBLIC:
977      * <p>
978      * Log a throwable with level.
979      * </p><p>
980      *
981      * @param level the log request level value
982      * </p><p>
983      * @param throwable a Throwable
984      * </p>
985      */

986     public void logThrowable(int level, Throwable JavaDoc throwable) {
987         // Must not create the log if not logging as is a performance issue.
988
if (shouldLog(level)) {
989             log(new SessionLogEntry(null, level, null, throwable));
990         }
991     }
992
993     /**
994      * PUBLIC:
995      * Check if the log level is set to off.
996      */

997     public boolean isOff() {
998         return this.level == OFF;
999     }
1000
1001    /**
1002     * INTERNAL:
1003     * Each session owns its own session log because session is stored in the session log
1004     */

1005    public Object JavaDoc clone() {
1006        try {
1007            return super.clone();
1008        } catch (Exception JavaDoc exception) {
1009            return null;
1010        }
1011    }
1012}
1013
Popular Tags