1 // Module:  Log4CPLUS
  2 // File:    loggerimpl.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 
 16 #ifndef _LOG4CPLUS_SPI_LOGGER_HEADER_
 17 #define _LOG4CPLUS_SPI_LOGGER_HEADER_
 18 
 19 #include <log4cplus/config.h>
 20 #include <log4cplus/logger.h>
 21 #include <log4cplus/tstring.h>
 22 #include <log4cplus/helpers/appenderattachableimpl.h>
 23 #include <log4cplus/helpers/pointer.h>
 24 #include <log4cplus/spi/loggerfactory.h>
 25 #include <memory>
 26 #include <vector>
 27 
 28 
 29 namespace log4cplus {
 30     namespace spi {
 31 
 32         /**
 33          * This is the central class in the log4cplus package. One of the
 34          * distintive features of log4cplus are hierarchical loggers and their
 35          * evaluation.
 36          *
 37          * <p>See the <a href="../../../../manual.html">user manual</a> for an
 38          * introduction on this class. 
 39          */
 40         class LOG4CPLUS_EXPORT LoggerImpl : public log4cplus::helpers::SharedObject,
 41                                             public log4cplus::helpers::AppenderAttachableImpl
 42         {
 43         public:
 44           // Methods
 45 
 46             /**
 47              * Call the appenders in the hierrachy starting at
 48              * <code>this</code>.  If no appenders could be found, emit a
 49              * warning.
 50              * <p>
 51              * This method calls all the appenders inherited from the
 52              * hierarchy circumventing any evaluation of whether to log or not
 53              * to log the particular log request.
 54              *                                   
 55              * @param spi::InternalLoggingEvent the event to log. 
 56              */
 57             virtual void callAppenders(const InternalLoggingEvent& event);
 58 
 59             /**
 60              * Close all attached appenders implementing the AppenderAttachable
 61              * interface.  
 62              */
 63             virtual void closeNestedAppenders();
 64 
 65             /**
 66              * Check whether this logger is enabled for a given LogLevel passed 
 67              * as parameter.
 68              *
 69              * @return boolean True if this logger is enabled for <code>ll</code>.
 70              */
 71             virtual bool isEnabledFor(LogLevel ll) const;
 72 
 73             /**
 74              * This generic form is intended to be used by wrappers. 
 75              */
 76             virtual void log(LogLevel ll, const log4cplus::tstring& message,
 77                              const char* file=NULL, int line=-1);
 78 
 79             /**
 80              * Starting from this logger, search the logger hierarchy for a
 81              * "set" LogLevel and return it. Otherwise, return the LogLevel of the
 82              * root logger.
 83              *                     
 84              * <p>The Logger class is designed so that this method executes as
 85              * quickly as possible.
 86              */
 87             virtual LogLevel getChainedLogLevel() const;
 88 
 89             /**
 90              * Returns the assigned LogLevel, if any, for this Logger.  
 91              *           
 92              * @return LogLevel - the assigned LogLevel.
 93              */
 94             LogLevel getLogLevel() const { return this->ll; }
 95 
 96             /**
 97              * Set the LogLevel of this Logger.
 98              */
 99             void setLogLevel(LogLevel _ll) { this->ll = _ll; }
100 
101             /**
102              * Return the the {@link Hierarchy} where this <code>Logger</code>
103              * instance is attached.
104              */
105             virtual Hierarchy& getHierarchy() const;
106 
107             /**
108              * Return the logger name.  
109              */
110             log4cplus::tstring getName() const { return name; }
111 
112             /**
113              * Get the additivity flag for this Logger instance.
114              */
115             bool getAdditivity() const;
116 
117             /**
118              * Set the additivity flag for this Logger instance.
119              */
120             void setAdditivity(bool additive);
121 
122             virtual ~LoggerImpl();
123 
124         protected:
125           // Ctors
126             /**
127              * This constructor created a new <code>Logger</code> instance and
128              * sets its name.
129              *
130              * <p>It is intended to be used by sub-classes only. You should not
131              * create loggers directly.
132              *
133              * @param name The name of the logger.  
134              */
135             LoggerImpl(const log4cplus::tstring& name, Hierarchy& h);
136 
137 
138           // Methods
139             /**
140              * This method creates a new logging event and logs the event
141              * without further checks.  
142              */
143             virtual void forcedLog(LogLevel ll,
144                                    const log4cplus::tstring& message,
145                                    const char* file=NULL, 
146                                    int line=-1);
147 
148 
149           // Data
150             /** The name of this logger */
151             log4cplus::tstring name;
152 
153             /**
154              * The assigned LogLevel of this logger.
155              */
156             LogLevel ll;
157 
158             /**
159              * The parent of this logger. All loggers have at least one
160              * ancestor which is the root logger. 
161              */ 
162             SharedLoggerImplPtr parent;
163 
164             /** 
165              * Additivity is set to true by default, that is children inherit
166              * the appenders of their ancestors by default. If this variable is
167              * set to <code>false</code> then the appenders found in the
168              * ancestors of this logger are not used. However, the children
169              * of this logger will inherit its appenders, unless the children
170              * have their additivity flag set to <code>false</code> too. See
171              * the user manual for more details. 
172              */
173             bool additive;
174 
175         private:
176           // Data
177             /** Loggers need to know what Hierarchy they are in. */
178             Hierarchy& hierarchy;
179 
180           // Disallow copying of instances of this class
181             LoggerImpl(const LoggerImpl&);
182             LoggerImpl& operator=(const LoggerImpl&);
183 
184           // Friends
185             friend class log4cplus::Logger;
186             friend class log4cplus::DefaultLoggerFactory;
187             friend class log4cplus::Hierarchy;
188         };
189 
190     } // end namespace spi
191 } // end namespace log4cplus
192 
193 #endif // _LOG4CPLUS_SPI_LOGGER_HEADER_


syntax highlighted by Code2HTML, v. 0.9.1