Utils/Logger: Reorganize source code
[senf.git] / Utils / Logger / Definitions.hh
1 // $Id$
2 //
3 // Copyright (C) 2007 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer NETwork research (NET)
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         private:                                                                                  \
64             stream() { init(); }                                                                  \
65             friend class senf::singleton<stream>;                                                 \
66         }
67
68     /** \brief Define log area
69
70         Defines a new log area named \a area. The area is defined as a symbol in the current scope.
71
72         \hideinitializer
73         \ingroup logging
74      */
75 #   define SENF_LOG_DEF_AREA(area) SENF_LOG_DEF_AREA_I(area, ; )
76
77     /** \brief Define new default log area for the class
78
79         This command declares the containing class to be it's own default log area. It is such like a
80         combination of \ref SENF_LOG_DEF_AREA and \ref SENF_LOG_DEFAULT_AREA with a twist.
81      */
82 #   define SENF_LOG_CLASS_AREA()                                                                  \
83         SENF_LOG_DEF_AREA_I(                                                                      \
84             SENFLogArea,                                                                          \
85             std::string v_name() const                                                            \
86                 { std::string s (fullName()); return std::string(s,0,s.size()-13); });            \
87         SENF_LOG_DEFAULT_AREA(SENFLogArea)
88
89
90     /** \brief Define log parameter alias
91
92         Defines a new parameter alias named \a alias as an alias for the parameters in \a args. The
93         alias is defined as a symbol in the current scope.
94
95         \hideinitializer
96      */
97 #   define SENF_LOG_DEF_ALIAS(alias,args)                                                         \
98         struct alias : public senf::log::detail::AliasBase                                        \
99         {                                                                                         \
100             template <class Base>                                                                 \
101             struct apply                                                                          \
102             {                                                                                     \
103                 typedef typename SENF_LOG_MERGE_PARAMETERS_I(Base,args) type;                     \
104             };                                                                                    \
105         }
106
107         /** \brief Default global log stream */
108         SENF_LOG_DEF_STREAM(Debug, MESSAGE, DISABLED, DISABLED);
109
110         /** \brief Default global log area */
111         SENF_LOG_DEF_AREA_I(DefaultArea,
112                             std::string v_name() const { return ""; });
113
114     ///\}
115     ///\}
116
117 }}
118
119 ///////////////////////////////hh.e////////////////////////////////////////
120 //#include "Definitions.cci"
121 //#include "Definitions.ct"
122 //#include "Definitions.cti"
123 #endif
124
125 \f
126 // Local Variables:
127 // mode: c++
128 // fill-column: 100
129 // comment-column: 40
130 // c-file-style: "senf"
131 // indent-tabs-mode: nil
132 // ispell-local-dictionary: "american"
133 // compile-command: "scons -u test"
134 // End: