4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief Config public header */
32 //#include "Config.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
36 /** \defgroup config Configuration
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.
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
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. Message routing is managed
49 via the \ref Target interface.
51 \section config_compile Compile time configuration
53 Compile time configuration is set on the compiler command line:
55 g++ ... -DSENF_LOG_CONF="(( (senf)(log)(Debug),(_),DISABLED ))
56 (( (senf)(log)(Debug),(foo)(SomeClass),VERBOSE ))
57 (( (foo)(Transactions),(_),NOTICE ))" ...
59 The value is relatively complex; It's a Boost.Preprocessor style sequence of tuples, of which
60 the first and second elements are again sequences. What this boils down to, is that it allows to
61 configure compile time logging limits based on stream and optional area.
63 The above example disables all debug logging by setting the default log limit for all areas on
64 the \c senf::log::Debug stream to \c DISABLED. It then re-enables debug logging only within the
65 \c foo::SomeClass area, where it is set to \c VERBOSE. Furthermore, the limit on the \c
66 foo::Transactions stream is set to \c NOTICE.
68 \section config_runtime Runtime configuration
70 The runtime configuration is performed by routing messages to one or more logging targets:
72 senf::log::ConsoleLog consoleLog;
73 senf::log::FileLog fileLog ("my.log");
75 consoleLog.route<senf::log::Debug>();
76 consoleLog.route<foo::Transactions, foo::SomeClass>(senf::log::Target::REJECT);
77 consoleLog.route<foo::Transactions, senf::log::IMPORTANT>();
79 fileLog.route<foo::Transactions>();
80 \endcode Here we see an already relatively complex setup: All debug messages (that is, those,
81 which are not disabled at compile time) are routed to the console. We also route important
82 transactions to the console \e except transactions from the \c foo::SomeClass area. The \c
83 fileLog simply receives all transaction log messages.
85 The routing statements are processed by the targets in order, the first matching rule will
86 decide a log messages fate for that target.
89 \ref SENF_LOG_CONF: compile time configuration \n
90 \ref senf::log::Target: runtime configuration
101 /** \brief Compile time configuration
103 This define symbol sets the compile time logger configuration. This symbol should normally
104 be set on the compiler command line.
106 The formal syntax of this option is:
110 <tr><td>conf</td> <td>::= \e element \e element* \n</td></tr>
111 <tr><td>element</td> <td>::= <tt>((</tt> \e stream <tt>,</tt> \e optional_area <tt>,</tt> \e level <tt>))</tt> \n</td></tr>
112 <tr><td>stream</td> <td>::= \e scope_seq \n</td></tr>
113 <tr><td>optional_area</td><td>::= <tt>(_)</tt> | \e scope_seq \n</td></tr>
114 <tr><td>level</td> <td>::= \c VERBOSE | \c NOTICE | \c MESSAGE | \c IMPORTANT | \c CRITICAL | \c DISABLED \n</td></tr>
115 <tr><td>scope_seq</td> <td>::= \e scope \e scope \e scope* \n</td></tr>
116 <tr><td>scope</td> <td>::= <tt>(</tt> \e name <tt>)</tt> \n</td></tr>
117 <tr><td>name</td> <td>::= arbitrary C++ identifier</td></tr>
120 \ref SENF_LOG_CONF is a Boost.Preprocessor style sequence of 3-tuples. Each tuple applies to
121 a specific stream which is defined by the first tuple element \e stream.
123 The next tuple element, \e optional_area optionally restricts the entry to match only the
126 The last tuple element \e level defines the compile time log level. Messages with a level
127 below this are discarded at compile time.
129 Both \e stream and \e optional_area are given as a \e scope_seq. A scope sequence is a fully
130 qualified C++ identifier placed into a sequence: <tt>foo::bar::baz</tt> is represented by
131 <tt>(foo)(bar)(baz)</tt>.
133 # define SENF_LOG_CONF
137 /** \brief Check, if logging is enabled for stream/area/level tuple
139 This is a template meta-function which will check, whether logging to the given combination
140 of parameters \a Stream, \a Area and \a Level is compile-time enabled. The logging might
141 still be disabled at runtime.
143 if (senf::log::Enabled<senf::log::Debug,
144 senf::log::DefaultArea,
145 senf::log::VERBOSE>::value) {
150 Since the \e value member is a compile time constant, the compiler will completely optimize
151 away this block of code when logging is disabled.
153 template <class Stream, class Area, class Level>
156 static const bool value = (
157 (Level::value == NONE::value ? Stream::defaultLevel::value : Level::value)
158 >= detail::Config<Stream,Area>::compileLimit::value );
165 ///////////////////////////////hh.e////////////////////////////////////////
166 //#include "Config.cci"
167 //#include "Config.ct"
168 //#include "Config.cti"
175 // comment-column: 40
176 // c-file-style: "senf"
177 // indent-tabs-mode: nil
178 // ispell-local-dictionary: "american"
179 // compile-command: "scons -u test"