log4cplus  1.1.0
appender.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // Module:  Log4CPLUS
00003 // File:    appender.h
00004 // Created: 6/2001
00005 // Author:  Tad E. Smith
00006 //
00007 //
00008 // Copyright 2001-2010 Tad E. Smith
00009 //
00010 // Licensed under the Apache License, Version 2.0 (the "License");
00011 // you may not use this file except in compliance with the License.
00012 // You may obtain a copy of the License at
00013 //
00014 //     http://www.apache.org/licenses/LICENSE-2.0
00015 //
00016 // Unless required by applicable law or agreed to in writing, software
00017 // distributed under the License is distributed on an "AS IS" BASIS,
00018 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019 // See the License for the specific language governing permissions and
00020 // limitations under the License.
00021 
00024 #ifndef LOG4CPLUS_APPENDER_HEADER_
00025 #define LOG4CPLUS_APPENDER_HEADER_
00026 
00027 #include <log4cplus/config.hxx>
00028 
00029 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
00030 #pragma once
00031 #endif
00032 
00033 #include <log4cplus/layout.h>
00034 #include <log4cplus/loglevel.h>
00035 #include <log4cplus/tstring.h>
00036 #include <log4cplus/helpers/pointer.h>
00037 #include <log4cplus/spi/filter.h>
00038 #include <log4cplus/helpers/lockfile.h>
00039 
00040 #include <memory>
00041 
00042 
00043 namespace log4cplus {
00044 
00045 
00046     namespace helpers
00047     {
00048 
00049         class Properties;
00050 
00051     }
00052 
00053 
00058     class LOG4CPLUS_EXPORT ErrorHandler
00059     {
00060     public:
00061         ErrorHandler ();
00062         virtual ~ErrorHandler() = 0;
00063         virtual void error(const log4cplus::tstring& err) = 0;
00064         virtual void reset() = 0;
00065     };
00066 
00067 
00068     class LOG4CPLUS_EXPORT OnlyOnceErrorHandler
00069         : public ErrorHandler
00070     {
00071     public:
00072       // Ctor
00073         OnlyOnceErrorHandler();
00074         virtual ~OnlyOnceErrorHandler ();
00075         virtual void error(const log4cplus::tstring& err);
00076         virtual void reset();
00077 
00078     private:
00079         bool firstTime;
00080     };
00081 
00082 
00129     class LOG4CPLUS_EXPORT Appender
00130         : public virtual log4cplus::helpers::SharedObject
00131     {
00132     public:
00133       // Ctor
00134         Appender();
00135         Appender(const log4cplus::helpers::Properties & properties);
00136 
00137       // Dtor
00138         virtual ~Appender();
00139 
00140         void destructorImpl();
00141 
00142       // Methods
00149         virtual void close() = 0;
00150 
00156         void doAppend(const log4cplus::spi::InternalLoggingEvent& event);
00157 
00162         virtual log4cplus::tstring getName();
00163 
00168         virtual void setName(const log4cplus::tstring& name);
00169 
00173         virtual void setErrorHandler(std::auto_ptr<ErrorHandler> eh);
00174 
00179         virtual ErrorHandler* getErrorHandler();
00180 
00186         virtual void setLayout(std::auto_ptr<Layout> layout);
00187 
00193         virtual Layout* getLayout();
00194 
00198         void setFilter(log4cplus::spi::FilterPtr f) { filter = f; }
00199 
00203         log4cplus::spi::FilterPtr getFilter() const { return filter; }
00204 
00209         LogLevel getThreshold() const { return threshold; }
00210 
00219         void setThreshold(LogLevel th) { threshold = th; }
00220 
00226         bool isAsSevereAsThreshold(LogLevel ll) const {
00227             return ((ll != NOT_SET_LOG_LEVEL) && (ll >= threshold));
00228         }
00229 
00230     protected:
00231       // Methods
00237         virtual void append(const log4cplus::spi::InternalLoggingEvent& event) = 0;
00238 
00239         tstring & formatEvent (const log4cplus::spi::InternalLoggingEvent& event) const;
00240 
00241       // Data
00244         std::auto_ptr<Layout> layout;
00245 
00247         log4cplus::tstring name;
00248 
00250         LogLevel threshold;
00251 
00254         log4cplus::spi::FilterPtr filter;
00255 
00257         std::auto_ptr<ErrorHandler> errorHandler;
00258 
00260         std::auto_ptr<helpers::LockFile> lockFile;
00261 
00264         bool useLockFile;
00265 
00267         bool closed;
00268     };
00269 
00271     typedef helpers::SharedObjectPtr<Appender> SharedAppenderPtr;
00272 
00273 } // end namespace log4cplus
00274 
00275 #endif // LOG4CPLUS_APPENDER_HEADER_
00276