Utils: Moved Logger into 'Logger/' submodule
[senf.git] / Utils / Logger / Log.hh
1 // $Id$
2 //
3 // Copyright (C) 2007 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
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 Log public header */
25
26 #ifndef HH_Log_
27 #define HH_Log_ 1
28
29 // Custom includes
30 #include <boost/preprocessor/seq/size.hpp>
31 #include <boost/preprocessor/dec.hpp>
32 #include <boost/preprocessor/seq/elem.hpp>
33 #include <boost/preprocessor/seq/pop_back.hpp>
34 #include "Parameters.hh"
35
36 //#include "Log.mpp"
37 ///////////////////////////////hh.p////////////////////////////////////////
38
39 /** \brief Write log message
40
41     This macro will write it's last argument to the log stream. The last argument must be an
42     expression which will be placed after a streaming \c operator<< (like
43     <i>some-log-sttream</i> \c << <i>last-macro-arg</i>).
44     \code
45     SENF_LOG((parameters...)("log message " << args << ...));
46     \endcode
47
48     \hideinitializer
49  */
50 #define SENF_LOG(args)                                                                            \
51     SENF_LOG_BLOCK_( SENF_LOG_MERGE_PARAMETERS(BOOST_PP_SEQ_POP_BACK(args)),                      \
52                      { log << BOOST_PP_SEQ_ELEM(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(args)),args); })
53
54 /** \brief Enable block based on logging parameters
55
56     This macro is like SENF_LOG, however instead of writing a simple message, this macro allows
57     to specify a complete block of code to be executed if the log message is enabled.
58     \code
59     SENF_LOG_BLOCK((parameters...)({
60        // arbitrary code using 'log' for logging
61        log << "log message";
62     }));
63     \endcode
64
65     \hideinitializer
66  */
67 #define SENF_LOG_BLOCK(args)                                                                      \
68     SENF_LOG_BLOCK_( SENF_LOG_MERGE_PARAMETERS(BOOST_PP_SEQ_POP_BACK(args)),                      \
69                      BOOST_PP_SEQ_ELEM(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(args)),args))
70
71 #define SENF_LOG_BLOCK_(parameters, block)                                                        \
72     do {                                                                                          \
73         if (parameters::compile_enabled && parameters::enabled()) {                               \
74             std::ostream & log (parameters::log_stream());                                         \
75             do block while(0);                                                                    \
76             log << std::endl;                                                                     \
77         }                                                                                         \
78     } while(0) 
79
80 ///////////////////////////////hh.e////////////////////////////////////////
81 //#include "Log.cci"
82 //#include "Log.ct"
83 //#include "Log.cti"
84 #endif
85
86 \f
87 // Local Variables:
88 // mode: c++
89 // fill-column: 100
90 // comment-column: 40
91 // c-file-style: "senf"
92 // indent-tabs-mode: nil
93 // ispell-local-dictionary: "american"
94 // compile-command: "scons -u test"
95 // End: