Utils/Logger: Reorganize source code
[senf.git] / Utils / Logger / Config.hh
1 // $Id$
2 //
3 // Copyright (C) 2007 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
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 Config public header */
25
26 #ifndef HH_Config_
27 #define HH_Config_ 1
28
29 // Custom includes
30 #include "Levels.hh"
31
32 //#include "Config.mpp"
33 #include "Config.ih"
34 ///////////////////////////////hh.p////////////////////////////////////////
35
36 /** \defgroup config Configuration
37
38     The logger infrastructure provides for very fine-grained configuration of log messages. There
39     are two parts to this configuration: compile-time configuration and runtime configuration.
40
41     <em>Compile-time</em> configuration selects, which log statements will even be compiled. If
42     logging for a certain combination of stream, area and level is disabled at compile time, no code
43     will be generated for any such disabled log statement. This type of configuration is done using
44     \ref SENF_LOG_CONF.
45
46     <em>Runtime</em> configuration on the other hand deals with routing all those messages, which
47     are enabled at compile time to the logging targets. If a message is not routed, it will be
48     discarded. This allows to additionally disable messages at run-time.
49  */
50
51 namespace senf {
52 namespace log {
53
54     ///\ingroup config
55     ///\{
56
57 #   ifdef DOXYGEN
58
59     /** \brief Compile time configuration
60
61         This define symbol sets the compile time logger configuration. This symbol should normally
62         be set on the compiler command line:
63         <pre>
64         g++ ... -DSENF_LOG_CONF="(( (senf)(log)(Debug),(_),DISABLED ))
65                                  (( (senf)(log)(Debug),(foo)(SomeClass),(VERBOSE) ))
66                                  (( (foo)(Transactions),(_),NOTICE ))" ...
67         </pre>
68         (As this option can get quite long, you might want to use the '-imacros' option instead)
69
70         The formal syntax of this option is:
71
72         \par ""
73             <table class="ebnf">
74             <tr><td>conf</td>         <td>::= \e element \e element* \n</td></tr>
75             <tr><td>element</td>      <td>::= <tt>((</tt> \e stream <tt>,</tt> \e optional_area <tt>,</tt> \e level <tt>))</tt> \n</td></tr>
76             <tr><td>stream</td>       <td>::= \e scope_seq \n</td></tr>
77             <tr><td>optional_area</td><td>::= <tt>(_)</tt> | \e scope_seq \n</td></tr>
78             <tr><td>level</td>        <td>::= \c VERBOSE | \c NOTICE | \c MESSAGE | \c IMPORTANT | \c CRITICAL | \c DISABLED \n</td></tr>
79             <tr><td>scope_seq</td>    <td>::= \e scope \e scope \e scope* \n</td></tr>
80             <tr><td>scope</td>        <td>::= <tt>(</tt> \e name <tt>)</tt> \n</td></tr>
81             <tr><td>name</td>         <td>::= arbitrary C++ identifier</td></tr>
82             </table>
83
84         \ref SENF_LOG_CONF is a Boost.Preprocessor style sequence of 3-tuples. Each tuple applies to
85         a specific stream which is defined by the first tuple element \e stream. 
86
87         The next tuple element, \e optional_area optionally restricts the entry to match only the
88         given area. 
89
90         The last tuple element \e level defines the compile time log level. Messages with a level
91         below this are discarded at compile time.
92
93         Both \e stream and \e optional_area are given as a \e scope_seq. A scope sequence is a fully
94         qualified C++ identifier placed into a sequence: <tt>foo::bar::baz</tt> is represented by
95         <tt>(foo)(bar)(baz)</tt>.
96      */
97 #   define SENF_LOG_CONF
98
99 #   endif
100
101     /** \brief Check, if logging is enabled for stream/area/level tuple
102         
103         This is a template meta-function which will check, whether logging to the given combination
104         of parameters \a Stream, \a Area and \a Level is compile-time enabled. The logging might
105         still be disabled at runtime.
106         \code
107         if (senf::log::Enabled<senf::log::Debug, 
108                                senf::log::DefaultArea, 
109                                senf::log::VERBOSE>::value) {
110             // ...
111         }
112         \endcode
113
114         Since the \e value member is a compile time constant, the compiler will completely optimize
115         away this block of code when logging is disabled.
116      */
117     template <class Stream, class Area, class Level>
118     struct Enabled
119     {
120         static const bool value = (
121             (Level::value == senf::log::NONE::value ? Stream::defaultLevel::value : Level::value)
122                 >= detail::Config<Stream,Area>::compileLimit::value );
123     };
124
125     ///\}
126
127 }}
128
129 ///////////////////////////////hh.e////////////////////////////////////////
130 //#include "Config.cci"
131 //#include "Config.ct"
132 //#include "Config.cti"
133 #endif
134
135 \f
136 // Local Variables:
137 // mode: c++
138 // fill-column: 100
139 // comment-column: 40
140 // c-file-style: "senf"
141 // indent-tabs-mode: nil
142 // ispell-local-dictionary: "american"
143 // compile-command: "scons -u test"
144 // End: