View Javadoc

1   /*   Open Source Java Caching Service
2   *    Copyright (C) 2002 Frank Karlstrøm
3   *    This library is free software; you can redistribute it and/or
4   *    modify it under the terms of the GNU Lesser General Public
5   *    License as published by the Free Software Foundation; either
6   *    version 2.1 of the License, or (at your option) any later version.
7   *
8   *    This library is distributed in the hope that it will be useful,
9   *    but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  *    Lesser General Public License for more details.
12  *
13  *    You should have received a copy of the GNU Lesser General Public
14  *    License along with this library; if not, write to the Free Software
15  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  *
17  *    The author can be contacted by email: fjankk@users.sourceforge.net
18  */
19  package javax.util.jcache;
20  
21  /**
22   * Applications can either extend this class to implement a customized logging
23   * mechanism. The caching service uses this API to log cache related events.
24   * Users can use the Cache.setLogSeverity(int) to change the desirable cache
25   * logging severity. The severity levels are defined as: OFF FATAL ERROR
26   * DEFAULT WARNING TRACE INFO DEBUG A default cache logger is implemented. If
27   * no cache logger is provided, the default cache logger will be used. By
28   * default, DefaultCacheLogger will log all the messages to a file called
29   * "jcache.log" in the directory where the server process is started. Users
30   * can set a differen log file name for the default logger when initializing
31   * the cache by calling CacheAttributes.setLogFileName(String).
32   * @todo all methods in this class should be implemented.
33   * @deprecated will be removed and replaced with jdk1.4 logging or log4j.
34   * @author Frank Karlstrøm
35   */
36  public abstract class CacheLogger {
37  
38      /** an int describing that the logging is off. */
39      public static final int OFF = 0;
40  
41      /** an int describing that only fatal errors should be logged. */
42      public static final int FATAL = 1;
43  
44      /** an int describing that only errors or higher should be logged. */
45      public static final int ERROR = 2;
46  
47      /** an int describing that only warnings or higher should be logged. */
48      public static final int WARNING = 3;
49  
50      /**
51       * an int describing that informational messages and higher should be
52       * logged.
53       */
54      public static final int INFO = 4;
55  
56      /**
57       * an int describing that default logging severity is applied. (info is
58       * default)
59       */
60      public static final int DEFAULT = 5;
61  
62      /** an int describing that debugmessages and higher should be logged. */
63      public static final int DEBUG = 6;
64  
65      /** an int describing that tracing messages and higher should be logged. */
66      public static final int TRACE = 7;
67  
68      /**
69       * Creates new CacheLogger.
70       */
71      protected CacheLogger() {
72      }
73  
74      /**
75       * application writers can implement this method and provide their own
76       * mechanism to log a message.
77       * 
78       * @param message the message to log.
79       */
80      public abstract void log(final String message);
81  
82      /**
83       * application writers can implement this method and provide their own
84       * mechanism to log a message.
85       * 
86       * @param message The message to log.
87       * @param cause The Exception responsible for causing an log event to
88       *            happen.
89       */
90      public abstract void log(final String message, final Throwable cause);
91  
92      /**
93       * is called by the caching system when the CacheLogger is instanciated to
94       * complete any initialization requirements.
95       *
96       * @param fileName the value from the CacheAttribute
97       * @param severity the value from the CacheAttributes.
98       * @todo Not supported.
99       */
100     public abstract void init(final String fileName, final int severity);
101 
102     /**
103      * log messages are buffered by the cache. This method will force the
104      * messages to be written out the destination and the buffer is reset.
105      * @todo Not supported.
106      */
107     public abstract void flush();
108 
109     /**
110      * returns the current severity level defined in this class. The severity
111      * level determines the amount of information that will be logged. The
112      * default setting is DEFAULT.
113      *
114      * @return the current severity level defined in this class.
115      * @todo Not supported.
116      */
117     public static int getSeverity() {
118         return OFF;
119     }
120 
121     /**
122      * sets the severity level to the specified level. The severity level
123      * determines the amount of information that will be logged. The default
124      * setting is DEFAULT.
125      *
126      * @param severity the severity level to set.
127      * @todo Not supported.
128      */
129     public final void setSeverity(final int severity) {
130     }
131 }