log4cplus  2.0.0
layout.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // Module:  Log4CPLUS
00003 // File:    Layout.h
00004 // Created: 6/2001
00005 // Author:  Tad E. Smith
00006 //
00007 //
00008 // Copyright 2001-2015 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_LAYOUT_HEADER_
00025 #define LOG4CPLUS_LAYOUT_HEADER_
00026 
00027 #include <log4cplus/config.hxx>
00028 
00029 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
00030 #pragma once
00031 #endif
00032 
00033 #include <log4cplus/loglevel.h>
00034 #include <log4cplus/streams.h>
00035 #include <log4cplus/tstring.h>
00036 #include <log4cplus/helpers/timehelper.h>
00037 
00038 #include <vector>
00039 #include <memory>
00040 
00041 
00042 namespace log4cplus {
00043 
00044     // Forward Declarations
00045     namespace pattern
00046     {
00047 
00048         class PatternConverter;
00049 
00050     }
00051 
00052 
00053     namespace helpers
00054     {
00055 
00056         class Properties;
00057 
00058     }
00059 
00060 
00061     namespace spi
00062     {
00063 
00064         class InternalLoggingEvent;
00065 
00066     }
00067 
00068 
00073     class LOG4CPLUS_EXPORT Layout
00074     {
00075     public:
00076         Layout();
00077         Layout(const helpers::Properties& properties);
00078         virtual ~Layout() = 0;
00079 
00080         virtual void formatAndAppend(log4cplus::tostream& output,
00081             const log4cplus::spi::InternalLoggingEvent& event) = 0;
00082 
00083     protected:
00084         LogLevelManager& llmCache;
00085 
00086     private:
00087       // Disable copy
00088         Layout(const Layout&);
00089         Layout& operator=(Layout const &);
00090     };
00091 
00092 
00093 
00104     class LOG4CPLUS_EXPORT SimpleLayout
00105         : public Layout
00106     {
00107     public:
00108         SimpleLayout();
00109         SimpleLayout(const log4cplus::helpers::Properties& properties);
00110         virtual ~SimpleLayout();
00111 
00112         virtual void formatAndAppend(log4cplus::tostream& output,
00113                                      const log4cplus::spi::InternalLoggingEvent& event);
00114 
00115     private:
00116       // Disallow copying of instances of this class
00117         SimpleLayout(const SimpleLayout&);
00118         SimpleLayout& operator=(const SimpleLayout&);
00119     };
00120 
00121 
00122 
00165     class LOG4CPLUS_EXPORT TTCCLayout
00166         : public Layout
00167     {
00168     public:
00169         TTCCLayout(bool use_gmtime = false, bool thread_printing = true,
00170             bool category_prefixes = true, bool context_printing = true);
00171         TTCCLayout(const log4cplus::helpers::Properties& properties);
00172         virtual ~TTCCLayout();
00173 
00174         virtual void formatAndAppend(log4cplus::tostream& output,
00175                                      const log4cplus::spi::InternalLoggingEvent& event);
00176 
00177         bool getThreadPrinting() const;
00178         void setThreadPrinting(bool);
00179 
00180         bool getCategoryPrefixing() const;
00181         void setCategoryPrefixing(bool);
00182 
00183         bool getContextPrinting() const;
00184         void setContextPrinting(bool);
00185 
00186     protected:
00187        log4cplus::tstring dateFormat;
00188        bool use_gmtime = false;
00189        bool thread_printing = true;
00190        bool category_prefixing = true;
00191        bool context_printing = true;
00192 
00193     private:
00194       // Disallow copying of instances of this class
00195         TTCCLayout(const TTCCLayout&);
00196         TTCCLayout& operator=(const TTCCLayout&);
00197     };
00198 
00199 
00200     LOG4CPLUS_EXPORT helpers::Time const & getTTCCLayoutTimeBase ();
00201 
00202 
00616     class LOG4CPLUS_EXPORT PatternLayout
00617         : public Layout
00618     {
00619     public:
00620       // Ctors and dtor
00621         PatternLayout(const log4cplus::tstring& pattern);
00622         PatternLayout(const log4cplus::helpers::Properties& properties);
00623         virtual ~PatternLayout();
00624 
00625         virtual void formatAndAppend(log4cplus::tostream& output,
00626                                      const log4cplus::spi::InternalLoggingEvent& event);
00627 
00628     protected:
00629         void init(const log4cplus::tstring& pattern, unsigned ndcMaxDepth = 0);
00630 
00631       // Data
00632         log4cplus::tstring pattern;
00633         std::vector<std::unique_ptr<pattern::PatternConverter> > parsedPattern;
00634 
00635     private:
00636       // Disallow copying of instances of this class
00637         PatternLayout(const PatternLayout&);
00638         PatternLayout& operator=(const PatternLayout&);
00639     };
00640 
00641 
00642 
00643 } // end namespace log4cplus
00644 
00645 #endif // LOG4CPLUS_LAYOUT_HEADER_