24c32f7d87ac0dec41f312c6bd7cedd83145fd53
[senf.git] / 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_Definitions_
27 #define HH_Definitions_ 1
28
29 // Custom includes
30
31 //#include "Definitions.mpp"
32 #include "Definitions.ih"
33 ///////////////////////////////hh.p////////////////////////////////////////
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         \hideinitializer
54      */
55 #   define SENF_LOG_DEF_STREAM(stream, defaultLevel_, runtimeLimit_, compileLimit_)               \
56         struct stream                                                                             \
57             : public senf::log::detail::StreamBase, public senf::singleton<stream>                \
58         {                                                                                         \
59             typedef defaultLevel_ defaultLevel;                                                   \
60             typedef runtimeLimit_ runtimeLimit;                                                   \
61             typedef compileLimit_ compileLimit;                                                   \
62             static std::string name() { return instance().v_name(); }                             \
63             unsigned defaultRuntimeLimit() const { return runtimeLimit::value; }                  \
64             using senf::singleton<stream>::instance;                                              \
65         private:                                                                                  \
66             stream() { init(); }                                                                  \
67             friend class senf::singleton<stream>;                                                 \
68         }
69
70     /** \brief Define log area
71
72         Defines a new log area named \a area. The area is defined as a symbol in the current scope.
73
74         \hideinitializer
75      */
76 #   define SENF_LOG_DEF_AREA(area) SENF_LOG_DEF_AREA_I(area, ; )
77
78     /** \brief Define new default log area for the class
79
80         This command declares the containing class to be it's own default log area. It is such like
81         a combination of \ref SENF_LOG_DEF_AREA and \ref SENF_LOG_DEFAULT_AREA with a twist.
82
83         \hideinitializer
84      */
85 #   define SENF_LOG_CLASS_AREA()                                                                  \
86         SENF_LOG_DEF_AREA_I(                                                                      \
87             SENFLogArea,                                                                          \
88             std::string v_name() const                                                            \
89                 { std::string s (fullName()); return std::string(s,0,s.size()-13); });            \
90         SENF_LOG_DEFAULT_AREA(SENFLogArea)
91
92
93     /** \brief Define log parameter alias
94
95         Defines a new parameter alias named \a alias as an alias for the parameters in \a args. The
96         alias is defined as a symbol in the current scope.
97
98         \hideinitializer
99      */
100 #   define SENF_LOG_DEF_ALIAS(alias,args)                                                         \
101         struct alias : public senf::log::detail::AliasBase                                        \
102         {                                                                                         \
103             template <class Base>                                                                 \
104             struct apply                                                                          \
105             {                                                                                     \
106                 typedef typename SENF_LOG_MERGE_PARAMETERS_I(Base,args) type;                     \
107             };                                                                                    \
108         }
109
110     /** \brief Default global log stream */
111     SENF_LOG_DEF_STREAM(Debug, MESSAGE, MESSAGE, MESSAGE);
112
113     /** \brief Default global %log area */
114     SENF_LOG_DEF_AREA(DefaultArea);
115
116     ///\}
117     ///\}
118
119 }}
120
121 ///////////////////////////////hh.e////////////////////////////////////////
122 //#include "Definitions.cci"
123 //#include "Definitions.ct"
124 //#include "Definitions.cti"
125 #endif
126
127 \f
128 // Local Variables:
129 // mode: c++
130 // fill-column: 100
131 // comment-column: 40
132 // c-file-style: "senf"
133 // indent-tabs-mode: nil
134 // ispell-local-dictionary: "american"
135 // compile-command: "scons -u test"
136 // End: