log4tango  4.0.3
Appender.hh
Go to the documentation of this file.
00001 //
00002 // Appender.hh
00003 //
00004 // Copyright (C) :  2000 - 2002
00005 //                                      LifeLine Networks BV (www.lifeline.nl). All rights reserved.
00006 //                                      Bastiaan Bakker. All rights reserved.   
00007 //                                      
00008 //                                      2004,2005,2006,2007,2008,2009,2010
00009 //                                      Synchrotron SOLEIL
00010 //                      L'Orme des Merisiers
00011 //                      Saint-Aubin - BP 48 - France
00012 //
00013 // This file is part of log4tango.
00014 //
00015 // Log4ango is free software: you can redistribute it and/or modify
00016 // it under the terms of the GNU Lesser General Public License as published by
00017 // the Free Software Foundation, either version 3 of the License, or
00018 // (at your option) any later version.
00019 // 
00020 // Log4tango is distributed in the hope that it will be useful,
00021 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 // GNU Lesser General Public License for more details.
00024 // 
00025 // You should have received a copy of the GNU Lesser General Public License
00026 // along with Log4Tango.  If not, see <http://www.gnu.org/licenses/>.
00027 
00028 #include <log4tango/Portability.hh>
00029 #include <string>
00030 #include <map>
00031 #include <set>
00032 #include <log4tango/Level.hh>
00033 #include <log4tango/Layout.hh>
00034 #include <log4tango/LoggingEvent.hh>
00035 #include <log4tango/threading/Threading.hh>
00036 
00037 #ifndef _LOG4TANGO_APPENDER_H
00038 #define _LOG4TANGO_APPENDER_H
00039 
00040 namespace log4tango {
00041 
00042 //-----------------------------------------------------------------------------
00043 // class : Appender
00044 //-----------------------------------------------------------------------------
00045 class LOG4TANGO_EXPORT Appender
00046 {
00047   friend class Logger;
00048   
00049 protected:
00055   Appender (const std::string& name);
00056 
00063   virtual void level_changed (Level::Value new_level);
00064   
00065 public:
00069   virtual ~Appender ();
00070         
00075 #if defined(APPENDERS_HAVE_LEVEL_THRESHOLD) || defined(APPENDERS_HAVE_FILTERS)
00076   int append (const LoggingEvent& event);
00077 #else
00078   inline int append (const LoggingEvent& event) {
00079     return _append(event);
00080   } 
00081 #endif
00082 
00088   virtual bool reopen (void);
00089 
00094   virtual void close (void) = 0;
00095 
00101   virtual bool requires_layout (void) const = 0;
00102 
00106   virtual void set_layout (Layout* layout = 0) = 0;
00107 
00111   inline const std::string& get_name (void) const {
00112     return _name;
00113   }
00114 
00122   virtual bool is_valid (void) const;
00123   
00124 #ifdef APPENDERS_HAVE_LEVEL_THRESHOLD
00125 
00131   void set_level (Level::Value level);
00132 
00137   Level::Value get_level (void) const;
00138 #endif // APPENDERS_HAVE_LEVEL_THRESHOLD
00139 
00140 #ifdef APPENDERS_HAVE_FILTERS
00141 
00144   virtual void set_filter (Filter* filter);
00145 
00150   virtual Filter* get_filter (void);
00151 #endif // APPENDERS_HAVE_FILTERS
00152 
00153 protected:
00159   virtual int _append(const LoggingEvent& event) = 0;
00160          
00161 private:
00165   const std::string _name;
00166 
00167 #ifdef APPENDERS_HAVE_LEVEL_THRESHOLD
00168 
00171   Level::Value _level;
00172 #endif
00173 
00174 #ifdef APPENDERS_HAVE_FILTERS
00175 
00178   Filter* _filter;
00179 #endif
00180 };
00181 
00182 } // namespace log4tango
00183 
00184 #endif // _LOG4TANGO_APPENDER_H