X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FLogger%2FLog.hh;fp=senf%2FUtils%2FLogger%2FLog.hh;h=da88f1ddcbcd30f18a8c98341f83776adeab71a3;hb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;hp=0000000000000000000000000000000000000000;hpb=164fe477094d42463722584e527a02379ab5d985;p=senf.git diff --git a/senf/Utils/Logger/Log.hh b/senf/Utils/Logger/Log.hh new file mode 100644 index 0000000..da88f1d --- /dev/null +++ b/senf/Utils/Logger/Log.hh @@ -0,0 +1,171 @@ +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief Log public header */ + +#ifndef HH_SENF_Utils_Logger_Log_ +#define HH_SENF_Utils_Logger_Log_ 1 + +// Custom includes +#include +#include +#include +#include +#include "Parameters.hh" + +//#include "Log.mpp" +#include "Log.ih" +///////////////////////////////hh.p//////////////////////////////////////// + +/** \defgroup logging Logging commands + + The logging library provides several commands to create %log messages. All these macro commands + take a variable number of arguments. Since this is not supported in a usable way by the C++ + preprocessor, the arguments are encoded into a Boost.Preprocessor like + sequence: + + \code + SENF_LOG( (senf::log::Debug)(senf::log::NOTICE)(FroblizerArea)("The log message") ); + \endcode + + The argument is comprised of a sequence of parameters and the %log message itself. + The parameters are + - the %log stream, + - the %log area, + - the %log level. + + These parameters are optional and may be specified in arbitrary order (with the %log + message always being the last sequence element) and even multiple times in the parameter + sequence. If some argument type occurs multiple times, the last occurrence wins. If any one of + the parameters is not specified, it's current default value will be used. + + This current default value is set using \ref SENF_LOG_DEFAULT_STREAM, \ref SENF_LOG_DEFAULT_AREA + and \ref SENF_LOG_DEFAULT_LEVEL respectively. These macros set the default stream, area and/or + level of the current scope. They may be used with a class declaration to set defaults + for all class members or within a function or member body to set the default for that member + only. They may be used only \e once within each scope. + + The logging library defines the global defaults for stream, area and level to be \c + senf::log::Debug, senf::log::DefaultArea, and senf::log::NONE respectively. + + The %log level senf::log::NONE is special. If the %log level is set to this value, the %log level + will be set from the stream provided default value. + + All these parameters must be compile time constants (they are all types, so it's + difficult for them to be something else). + + \section logging_aliases Aliases + + To further simplify logging commands, aliases may be defined within any scope. An alias is an + arbitrary collection of %log parameters: + \code + SENF_LOG_DEFINE_ALIAS( VerboseDebug, (senf::log::Debug)(senf::log::VERBOSE) ); + \endcode + Within %log statements, aliases may be used like normal parameters. They will be substituted for + the parameter sequence they represent: + \code + SENF_LOG( (VerboseDebug)("Debug message") ) + // is equivalent to + SENF_LOG( (senf::log::Debug)(senf::log::VERBOSE)("Debug message") ) + \endcode + Aliases may be used together with other parameters, even with further aliases in any order. + */ + +///\addtogroup logging +///\{ + +///\name Generating log messages +///\{ + +/** \brief Write log message + + This macro will write it's last argument to the log stream. The last argument must be an + expression which will be placed after a streaming \c operator<< (like + some-log-stream \c << last-macro-arg). + \code + SENF_LOG((parameters...)("log message " << args << ...)); + \endcode + + \hideinitializer + */ +#define SENF_LOG(args) \ + SENF_LOG_BLOCK_( SENF_LOG_MERGE_PARAMETERS(BOOST_PP_SEQ_POP_BACK(args)), \ + { log << BOOST_PP_SEQ_ELEM(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(args)),args); }) + +/** \brief Write log message (template context) + + This macro is used like \ref SENF_LOG() if called from a template context + + \hideinitializer + */ +#define SENF_LOG_TPL(args) \ + SENF_LOG_BLOCK_TPL_( SENF_LOG_MERGE_PARAMETERS_TPL(BOOST_PP_SEQ_POP_BACK(args)), \ + { log << BOOST_PP_SEQ_ELEM(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(args)),args); }) + +/** \brief Enable block based on logging parameters + + This macro is like SENF_LOG, however instead of writing a simple message, this macro allows + to specify a complete block of code to be executed if the log message is enabled. + \code + SENF_LOG_BLOCK((parameters...)({ + // arbitrary code using 'log' for logging + log << "log message"; + })); + \endcode + + \hideinitializer + */ +#define SENF_LOG_BLOCK(args) \ + SENF_LOG_BLOCK_( SENF_LOG_MERGE_PARAMETERS(BOOST_PP_SEQ_POP_BACK(args)), \ + BOOST_PP_SEQ_ELEM(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(args)),args)) + +/** \brief Write log message (template context) + + This macro is used like \ref SENF_LOG_BLOCK() if called from a template context + + \hideinitializer + */ +#define SENF_LOG_BLOCK_TPL(args) \ + SENF_LOG_BLOCK_TPL_( SENF_LOG_MERGE_PARAMETERS_TPL(BOOST_PP_SEQ_POP_BACK(args)), \ + BOOST_PP_SEQ_ELEM(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(args)),args)) + +///\} +///\} + +///////////////////////////////hh.e//////////////////////////////////////// +//#include "Log.cci" +//#include "Log.ct" +//#include "Log.cti" +#endif + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: