Logger: added SENF_LOG_DEFINE_NAMED_AREA macro
[senf.git] / senf / Utils / Logger / Definitions.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
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 Definitions public header */
30
31 #ifndef HH_SENF_Utils_Logger_Definitions_
32 #define HH_SENF_Utils_Logger_Definitions_ 1
33
34 // Custom includes
35
36 //#include "Definitions.mpp"
37 #include "Definitions.ih"
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39
40 namespace senf {
41 namespace log {
42
43     ///\addtogroup logging
44     //\{
45     ///\name Defining logger objects
46     //\{
47
48     /** \brief Define log stream
49
50         Defines a new log stream named \a stream. The stream is defined as a symbol in the current
51         scope.
52
53         \a defaultLevel defines the default log level for messages posted to this stream. \a
54         runtimeLimit defines the default log limit. Messages with a level below this will not be
55         output.  \a compileLimit defines the default log level limit at compile time: Messages
56         posted with a level below \a compileLimit will be discarded at compile time.
57
58         Normally the \a compileLimit will be \c NOTICE. This will enable all messages
59         <em>except</em> \c VERBOSE messages. These must then be enabled explicitly using the compile
60         time \ref config macro.
61
62         \hideinitializer
63      */
64 #   define SENF_LOG_DEFINE_STREAM(stream, defaultLevel_, runtimeLimit_, compileLimit_)            \
65         struct stream                                                                             \
66             : public senf::log::detail::StreamBase, public senf::singleton<stream>                \
67         {                                                                                         \
68             typedef defaultLevel_ defaultLevel;                                                   \
69             typedef runtimeLimit_ runtimeLimit;                                                   \
70             typedef compileLimit_ compileLimit;                                                   \
71             static std::string name() { return instance().v_name(); }                             \
72             unsigned defaultRuntimeLimit() const { return runtimeLimit::value; }                  \
73             using senf::singleton<stream>::instance;                                              \
74         private:                                                                                  \
75             stream() { init(); }                                                                  \
76             friend class senf::singleton<stream>;                                                 \
77         }
78
79     /** \brief Define log area
80
81         Defines a new log area named \a area. The area is defined as a symbol in the current scope.
82
83         \hideinitializer
84      */
85 #   define SENF_LOG_DEFINE_AREA(area) SENF_LOG_DEFINE_AREA_I(area, ; )
86
87 #   define SENF_LOG_DEFINE_NAMED_AREA(area, name)                                                 \
88         SENF_LOG_DEFINE_AREA_I(area,                                                              \
89             std::string v_name() const { return name; } );
90
91     /** \brief Define new default log area for the class
92
93         This command declares the containing class to be it's own default log area. It is such like
94         a combination of \ref SENF_LOG_DEFINE_AREA and \ref SENF_LOG_DEFAULT_AREA with a twist.
95
96         \hideinitializer
97      */
98     // See Definitions.ih for implementation details on SENF_LOG_CLASS_AREA
99 #   define SENF_LOG_CLASS_AREA()                                                                  \
100         SENF_LOG_DEFINE_AREA_I(                                                                   \
101             SENFLogArea,                                                                          \
102             std::string v_name() const                                                            \
103                 { std::string s (fullName()); return std::string(s,0,s.size()-13); });            \
104         SENF_LOG_DEFAULT_AREA(SENFLogArea)
105
106
107     /** \brief Define log parameter alias
108
109         Defines a new parameter alias named \a alias as an alias for the parameters in \a args. The
110         alias is defined as a symbol in the current scope.
111
112         \hideinitializer
113      */
114 #   define SENF_LOG_DEFINE_ALIAS(alias,args)                                                      \
115         struct alias : public senf::log::detail::AliasBase                                        \
116         {                                                                                         \
117             template <class Base>                                                                 \
118             struct apply                                                                          \
119             {                                                                                     \
120                 typedef typename SENF_LOG_MERGE_PARAMETERS_I(Base,args) type;                     \
121             };                                                                                    \
122         }
123
124     /** \brief Default global log stream */
125     SENF_LOG_DEFINE_STREAM(Debug, MESSAGE, MESSAGE, NOTICE);
126
127     /** \brief Default global %log area */
128     SENF_LOG_DEFINE_AREA(DefaultArea);
129
130     //\}
131     //\}
132
133 }}
134
135 //-/////////////////////////////////////////////////////////////////////////////////////////////////
136 //#include "Definitions.cci"
137 //#include "Definitions.ct"
138 //#include "Definitions.cti"
139 #endif
140
141 \f
142 // Local Variables:
143 // mode: c++
144 // fill-column: 100
145 // comment-column: 40
146 // c-file-style: "senf"
147 // indent-tabs-mode: nil
148 // ispell-local-dictionary: "american"
149 // compile-command: "scons -u test"
150 // End: