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