Utils/Logger: Add console directory to target
[senf.git] / Utils / Logger / LogFormat.hh
1 // $Id$
2 //
3 // Copyright (C) 2009 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief LogFormat public header */
25
26 #ifndef HH_SENF_Utils_Logger_LogFormat_
27 #define HH_SENF_Utils_Logger_LogFormat_ 1
28
29 // Custom includes
30 #include <sstream>
31 #include "Target.hh"
32
33 //#include "LogFormat.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
35
36 namespace senf {
37 namespace log {
38 namespace detail {
39
40     class LogFormat
41     {
42     public:
43         LogFormat();
44
45         void showTime(bool flag = true); ///< Enable or disable output of time field
46         void showStream(bool flag = true); ///< Enable or disable output of stream field
47         void showLevel(bool flag = true); ///< Enable or disable output of log level
48         void showArea(bool flag = true); ///< Enable or disable output of log area
49
50         void timeFormat(std::string const & format);
51                                         ///< Set time format
52                                         /**< The date formatting is set using the Boost.DateTime
53                                              date_facet, e.g.
54                                              \code
55                                                  target.timeFormat("%Y%m%d %H:%M:%S");
56                                              \endcode
57                                              If the \c timeFormat is set to the empty string, the
58                                              time is written out as unformatted ClockService value.
59
60                                              By default, the date-time will be written in extended
61                                              ISO format.
62                                              \param[in] format Date/Time format string */
63
64         void tag(std::string const & tag); ///< Set tag (log line prefix)
65
66     protected:
67         std::string prefix(time_type timestamp, std::string const & stream, 
68                            std::string const & area, unsigned level);
69         bool isPlainFormat() const;
70
71     private:
72         std::string tag_;
73         std::stringstream datestream_;
74         bool noformat_;
75         bool showTime_;
76         bool showStream_;
77         bool showLevel_;
78         bool showArea_;
79         time_type timeBase_;
80     };
81
82     void quoteNonPrintable(std::string & s);
83     std::string getDefaultTag();
84
85 }}}
86
87 ///////////////////////////////hh.e////////////////////////////////////////
88 #include "LogFormat.cci"
89 //#include "LogFormat.ct"
90 //#include "LogFormat.cti"
91 #endif
92
93 \f
94 // Local Variables:
95 // mode: c++
96 // fill-column: 100
97 // comment-column: 40
98 // c-file-style: "senf"
99 // indent-tabs-mode: nil
100 // ispell-local-dictionary: "american"
101 // compile-command: "scons -u test"
102 // End: