log4tango 4.0.3
PatternLayout.hh
Go to the documentation of this file.
00001 //
00002 // PatternLayout.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 #ifndef _LOG4TANGO_PATTERNLAYOUT_H
00029 #define _LOG4TANGO_PATTERNLAYOUT_H
00030 
00031 #include <log4tango/Portability.hh>
00032 #include <log4tango/Layout.hh>
00033 #include <vector>
00034 #ifdef LOG4TANGO_HAVE_SSTREAM
00035 # include <sstream>
00036 #endif
00037 
00038 namespace log4tango {
00039 
00040 //-----------------------------------------------------------------------------
00041 // class : PatternLayout (a simple fixed format Layout implementation)
00042 //-----------------------------------------------------------------------------  
00043 class LOG4TANGO_EXPORT PatternLayout : public Layout 
00044 {
00045 public:
00046 
00050   static const char* BASIC_CONVERSION_PATTERN;
00051 
00052   PatternLayout();
00053 
00054   virtual ~PatternLayout();
00055         
00056   // NOTE: 
00057   // All double percentage signs ('%%') followed by a character
00058   // in the following comments should actually be a single char.
00059   // The doubles are included so that doxygen will print them correctly.
00060 
00066   virtual std::string format(const LoggingEvent& event);
00067 
00093   virtual int set_conversion_pattern (const std::string& conversionPattern);
00094 
00095   virtual std::string get_conversion_pattern() const;
00096 
00097   virtual void clear_conversion_pattern();
00098 
00099   class LOG4TANGO_EXPORT PatternComponent {
00100     public:
00101       inline virtual ~PatternComponent() {};
00102       virtual void append(std::ostringstream& out, const LoggingEvent& event) = 0;
00103   };
00104 
00105   private:
00106     typedef std::vector<PatternComponent*> ComponentVector; 
00107     ComponentVector _components;
00108     std::string _conversionPattern;
00109 }; 
00110        
00111 } // namespace log4tango 
00112 
00113 #endif // _LOG4TANGO_PATTERNLAYOUT_H