switch to new MPL based Fraunhofer FOKUS Public License
[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     /** \brief Define new default log area for the class
88
89         This command declares the containing class to be it's own default log area. It is such like
90         a combination of \ref SENF_LOG_DEFINE_AREA and \ref SENF_LOG_DEFAULT_AREA with a twist.
91
92         \hideinitializer
93      */
94     // See Definitions.ih for implementation details on SENF_LOG_CLASS_AREA
95 #   define SENF_LOG_CLASS_AREA()                                                                  \
96         SENF_LOG_DEFINE_AREA_I(                                                                   \
97             SENFLogArea,                                                                          \
98             std::string v_name() const                                                            \
99                 { std::string s (fullName()); return std::string(s,0,s.size()-13); });            \
100         SENF_LOG_DEFAULT_AREA(SENFLogArea)
101
102
103     /** \brief Define log parameter alias
104
105         Defines a new parameter alias named \a alias as an alias for the parameters in \a args. The
106         alias is defined as a symbol in the current scope.
107
108         \hideinitializer
109      */
110 #   define SENF_LOG_DEFINE_ALIAS(alias,args)                                                      \
111         struct alias : public senf::log::detail::AliasBase                                        \
112         {                                                                                         \
113             template <class Base>                                                                 \
114             struct apply                                                                          \
115             {                                                                                     \
116                 typedef typename SENF_LOG_MERGE_PARAMETERS_I(Base,args) type;                     \
117             };                                                                                    \
118         }
119
120     /** \brief Default global log stream */
121     SENF_LOG_DEFINE_STREAM(Debug, MESSAGE, MESSAGE, NOTICE);
122
123     /** \brief Default global %log area */
124     SENF_LOG_DEFINE_AREA(DefaultArea);
125
126     //\}
127     //\}
128
129 }}
130
131 //-/////////////////////////////////////////////////////////////////////////////////////////////////
132 //#include "Definitions.cci"
133 //#include "Definitions.ct"
134 //#include "Definitions.cti"
135 #endif
136
137 \f
138 // Local Variables:
139 // mode: c++
140 // fill-column: 100
141 // comment-column: 40
142 // c-file-style: "senf"
143 // indent-tabs-mode: nil
144 // ispell-local-dictionary: "american"
145 // compile-command: "scons -u test"
146 // End: