switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / Logger / LogFormat.hh
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief LogFormat public header */
30
31 #ifndef HH_SENF_Utils_Logger_LogFormat_
32 #define HH_SENF_Utils_Logger_LogFormat_ 1
33
34 // Custom includes
35 #include <sstream>
36 #include "TimeSource.hh"
37 #include <senf/Utils/Console/LazyDirectory.hh>
38
39 //#include "LogFormat.mpp"
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
41
42 namespace senf {
43 namespace log {
44 namespace detail {
45
46     class LogFormat
47     {
48     public:
49         LogFormat();
50         explicit LogFormat(console::ScopedDirectory<> & dir);
51
52         void showTime(bool flag = true); ///< Enable or disable output of time field
53         void showStream(bool flag = true); ///< Enable or disable output of stream field
54         void showLevel(bool flag = true); ///< Enable or disable output of log level
55         void showArea(bool flag = true); ///< Enable or disable output of log area
56
57         void timeFormat(std::string const & format);
58                                         ///< Set time format
59                                         /**< The date formatting is set using the Boost.DateTime
60                                              date_facet, e.g.
61                                              \code
62                                                  target.timeFormat("%Y%m%d %H:%M:%S");
63                                              \endcode
64                                              If the \c timeFormat is set to the empty string, the
65                                              time is written out as unformatted ClockService value.
66
67                                              By default, the date-time will be written in extended
68                                              ISO format.
69                                              \param[in] format Date/Time format string */
70
71         void tag(std::string const & tag); ///< Set tag (log line prefix)
72
73     protected:
74         std::string prefix(time_type timestamp, std::string const & stream,
75                            std::string const & area, unsigned level);
76         bool isPlainFormat() const;
77         void consoleFormat(std::ostream & os);
78
79     private:
80
81         std::string tag_;
82         std::string timeFormat_;
83         std::stringstream datestream_;
84         bool noformat_;
85         bool showTime_;
86         bool showStream_;
87         bool showLevel_;
88         bool showArea_;
89         time_type timeBase_;
90     };
91
92     void quoteNonPrintable(std::string & s);
93     std::string getDefaultTag();
94
95 }}}
96
97 //-/////////////////////////////////////////////////////////////////////////////////////////////////
98 #include "LogFormat.cci"
99 //#include "LogFormat.ct"
100 //#include "LogFormat.cti"
101 #endif
102
103 \f
104 // Local Variables:
105 // mode: c++
106 // fill-column: 100
107 // comment-column: 40
108 // c-file-style: "senf"
109 // indent-tabs-mode: nil
110 // ispell-local-dictionary: "american"
111 // compile-command: "scons -u test"
112 // End: