00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00016 #ifndef _LOG4CPLUS_APPENDER_HEADER_
00017 #define _LOG4CPLUS_APPENDER_HEADER_
00018
00019 #include <log4cplus/config.h>
00020 #include <log4cplus/layout.h>
00021 #include <log4cplus/loglevel.h>
00022 #include <log4cplus/tstring.h>
00023 #include <log4cplus/helpers/logloguser.h>
00024 #include <log4cplus/helpers/pointer.h>
00025 #include <log4cplus/helpers/property.h>
00026 #include <log4cplus/spi/filter.h>
00027
00028 #include <memory>
00029
00030
00031 namespace log4cplus {
00032
00037 class LOG4CPLUS_EXPORT ErrorHandler {
00038 public:
00039 virtual ~ErrorHandler();
00040 virtual void error(const log4cplus::tstring& err) = 0;
00041 };
00042
00043
00044
00045 class LOG4CPLUS_EXPORT OnlyOnceErrorHandler : public ErrorHandler,
00046 protected log4cplus::helpers::LogLogUser
00047 {
00048 public:
00049
00050 OnlyOnceErrorHandler() : firstTime(true){}
00051
00052 virtual void error(const log4cplus::tstring& err);
00053
00054 private:
00055 bool firstTime;
00056 };
00057
00058
00063 class LOG4CPLUS_EXPORT Appender : public log4cplus::helpers::SharedObject,
00064 protected log4cplus::helpers::LogLogUser
00065
00066 {
00067 public:
00068
00069 Appender();
00070 Appender(const log4cplus::helpers::Properties properties);
00071
00072
00073 virtual ~Appender(){};
00074
00075 void destructorImpl();
00076
00077
00084 virtual void close() = 0;
00085
00091 void doAppend(const log4cplus::spi::InternalLoggingEvent& event);
00092
00097 virtual log4cplus::tstring getName();
00098
00103 virtual void setName(const log4cplus::tstring& name);
00104
00108 virtual void setErrorHandler(std::auto_ptr<ErrorHandler> eh);
00109
00114 virtual ErrorHandler* getErrorHandler();
00115
00121 virtual void setLayout(std::auto_ptr<Layout> layout);
00122
00128 virtual Layout* getLayout();
00129
00133 void setFilter(log4cplus::spi::FilterPtr f) { filter = f; }
00134
00138 log4cplus::spi::FilterPtr getFilter() const { return filter; }
00139
00144 LogLevel getThreshold() const { return threshold; }
00145
00154 void setThreshold(LogLevel th) { threshold = th; }
00155
00161 bool isAsSevereAsThreshold(LogLevel ll) const {
00162 return ((ll != NOT_SET_LOG_LEVEL) && (ll >= threshold));
00163 }
00164
00165 protected:
00166
00172 virtual void append(const log4cplus::spi::InternalLoggingEvent& event) = 0;
00173
00174
00177 std::auto_ptr<Layout> layout;
00178
00180 log4cplus::tstring name;
00181
00183 LogLevel threshold;
00184
00187 log4cplus::spi::FilterPtr filter;
00188
00190 std::auto_ptr<ErrorHandler> errorHandler;
00191
00193 bool closed;
00194 };
00195
00197 typedef helpers::SharedObjectPtr<Appender> SharedAppenderPtr;
00198
00199 }
00200
00201 #endif // _LOG4CPLUS_APPENDER_HEADER_
00202