1 // Module:  Log4CPLUS
  2 // File:    loglevel.h
  3 // Created: 6/2001
  4 // Author:  Tad E. Smith
  5 //
  6 //
  7 // Copyright (C) Tad E. Smith  All rights reserved.
  8 //
  9 // This software is published under the terms of the Apache Software
 10 // License version 1.1, a copy of which has been included with this
 11 // distribution in the LICENSE.APL file.
 12 //
 13 
 14 /** @file 
 15  * This header defines the LogLevel type.
 16  */
 17 
 18 #ifndef LOG4CPLUS_LOGLEVEL_HEADER_
 19 #define LOG4CPLUS_LOGLEVEL_HEADER_
 20 
 21 #include <log4cplus/config.h>
 22 #include <log4cplus/streams.h>
 23 #include <log4cplus/tstring.h>
 24 
 25 #include <vector>
 26 
 27 namespace log4cplus {
 28 
 29     /** 
 30      * \typedef int LogLevel
 31      * Defines the minimum set of priorities recognized by the system,
 32      * that is {@link #FATAL_LOG_LEVEL}, {@link #ERROR_LOG_LEVEL}, {@link
 33      * #WARN_LOG_LEVEL}, {@link #INFO_LOG_LEVEL}, {@link #DEBUG_LOG_LEVEL}, 
 34      * and {@link #TRACE_LOG_LEVEL}.
 35      */
 36     typedef int LogLevel;
 37 
 38     /** \var const LogLevel OFF_LOG_LEVEL
 39      * The <code>OFF_LOG_LEVEL</code> LogLevel is used during configuration to
 40      * turn off logging. */
 41     const LogLevel OFF_LOG_LEVEL     = 60000;
 42 
 43     /** \var const LogLevel FATAL_LOG_LEVEL
 44      * The <code>FATAL_LOG_LEVEL</code> LogLevel designates very severe error
 45      * events that will presumably lead the application to abort.  */
 46     const LogLevel FATAL_LOG_LEVEL   = 50000;
 47 
 48     /** \var const LogLevel ERROR_LOG_LEVEL
 49      * The <code>ERROR_LOG_LEVEL</code> LogLevel designates error events that
 50      * might still allow the application to continue running. */
 51     const LogLevel ERROR_LOG_LEVEL   = 40000;
 52 
 53     /** \var const LogLevel WARN_LOG_LEVEL
 54      * The <code>WARN_LOG_LEVEL</code> LogLevel designates potentially harmful 
 55      * situations. */
 56     const LogLevel WARN_LOG_LEVEL    = 30000;
 57 
 58     /** \var const LogLevel INFO_LOG_LEVEL
 59      * The <code>INFO_LOG_LEVEL</code> LogLevel designates informational 
 60      * messages  that highlight the progress of the application at 
 61      * coarse-grained  level. */
 62     const LogLevel INFO_LOG_LEVEL    = 20000;
 63 
 64     /** \var const LogLevel DEBUG_LOG_LEVEL
 65      * The <code>DEBUG_LOG_LEVEL</code> LogLevel designates fine-grained
 66      * informational events that are most useful to debug an application. */
 67     const LogLevel DEBUG_LOG_LEVEL   = 10000;
 68 
 69     /** \var const LogLevel TRACE_LOG_LEVEL
 70      * The <code>TRACE_LOG_LEVEL</code> LogLevel is used to "trace" entry
 71      * and exiting of methods. */
 72     const LogLevel TRACE_LOG_LEVEL   = 0;
 73     
 74     /** \var const LogLevel ALL_LOG_LEVEL
 75      * The <code>ALL_LOG_LEVEL</code> LogLevel is used during configuration to
 76      * turn on all logging. */
 77     const LogLevel ALL_LOG_LEVEL     = TRACE_LOG_LEVEL;
 78 
 79     /** \var const LogLevel NOT_SET_LOG_LEVEL
 80      * The <code>NOT_SET_LOG_LEVEL</code> LogLevel is used to indicated that
 81      * no particular LogLevel is desired and that the default should be used.
 82      */
 83     const LogLevel NOT_SET_LOG_LEVEL = -1;
 84 
 85 
 86     /** 
 87      * This method type defined the signature of methods that convert LogLevels
 88      * into strings. 
 89      * <p>
 90      * <b>Note:</b> Must return an empty <code>tstring</code> for unrecognized values.
 91      */
 92     typedef log4cplus::tstring (*LogLevelToStringMethod)(LogLevel);
 93 
 94     /** 
 95      * This method type defined the signature of methods that convert strings
 96      * into LogLevels. 
 97      * <p>
 98      * <b>Note:</b> Must return <code>NOT_SET_LOG_LEVEL</code> for unrecognized values.
 99      */
100     typedef LogLevel (*StringToLogLevelMethod)(const log4cplus::tstring&);
101 
102     
103 
104     /**
105      * This class is used to "manage" LogLevel definitions.  This class is also
106      * how "derived" LogLevels are created. Here are the steps to creating a
107      * "derived" LogLevel:
108      * <ol>
109      *   <li>Create a LogLevel constant (greater than 0)</li>
110      *   <li>Define a string to represent that constant</li>
111      *   <li>Implement a LogLevelToStringMethod method.</li>
112      *   <li>Implement a StringToLogLevelMethod method.</li>
113      *   <li>create a "static initializer" that registers those 2 methods
114      *       with the LogLevelManager singleton.</li>
115      * </ol>
116      */
117     class LOG4CPLUS_EXPORT LogLevelManager {
118     public:
119         LogLevelManager();
120         ~LogLevelManager();
121 
122         /**
123          * This method is called by all Layout classes to convert a LogLevel
124          * into a string.
125          * <p>
126          * Note: It traverses the list of <code>LogLevelToStringMethod</code>
127          *       to do this, so all "derived" LogLevels are recognized as well.
128          */
129         log4cplus::tstring toString(LogLevel ll) const;
130         
131         /**
132          * This method is called by all classes internally to log4cplus to
133          * convert a string into a LogLevel.
134          * <p>
135          * Note: It traverses the list of <code>StringToLogLevelMethod</code>
136          *       to do this, so all "derived" LogLevels are recognized as well.
137          */
138         LogLevel fromString(const log4cplus::tstring& s) const;
139 
140         /**
141          * When creating a "derived" LogLevel, a <code>LogLevelToStringMethod</code>
142          * should be defined and registered with the LogLevelManager by calling
143          * this method.
144          * <p>
145          * @see pushFromStringMethod
146          */
147         void pushToStringMethod(LogLevelToStringMethod newToString);
148 
149         /**
150          * When creating a "derived" LogLevel, a <code>StringToLogLevelMethod</code>
151          * should be defined and registered with the LogLevelManager by calling
152          * this method.
153          * <p>
154          * @see pushToStringMethod
155          */
156         void pushFromStringMethod(StringToLogLevelMethod newFromString);
157 
158     private:
159       // Data
160         void* toStringMethods;
161         void* fromStringMethods;
162 
163       // Disable Copy
164         LogLevelManager(const LogLevelManager&);
165    LogLevelManager& operator=(const LogLevelManager&);
166     };
167 
168     /**
169      * Returns the singleton LogLevelManager.
170      */
171     LOG4CPLUS_EXPORT LogLevelManager& getLogLevelManager();
172 
173 }
174 
175 
176 #endif // LOG4CPLUS_LOGLEVEL_HEADER_


syntax highlighted by Code2HTML, v. 0.9.1