// $Id$ // // Copyright (C) 2007 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) // Kompetenzzentrum fuer Satelitenkommunikation (SatCom) // 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. /** \mainpage The SENF Logging library The Loggger infrastructure implements a highly flexible compile- and run-time configurable logging infrastructure supporting multiple streams, user definable log areas and fine grained log levels. Logging can be configured at compile and runtime on any combination of above parameters. The library supports a host of log targets and messages can be routed into multiple targets at the same time. To allow concise usage of the library, a utility to define logging defaults for any scope is provided. An important basic concept of the library is, that most of the macros take a variable number of arguments. Since this is not supported in the needed manner 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 last sequence element always is the log message. Before that we have a number of log parameters in arbitrary order. Since giving all the parameters in every log message is to verbose, there are two helpful constructs to reduce the verbosity. Using \ref SENF_LOG_DEFAULT_STREAM, \ref SENF_LOG_DEFAULT_AREA and \ref SENF_LOG_DEFAULT_LEVEL it is possible to define the default logging parameters to be used within a given scope. Using \ref SENF_LOG_DEF_ALIAS you can define an alias (which is a scoped symbol) as an arbitrary combination of parameters. \code SENF_LOG_DEF_STREAM( userLog, senf::log::MESSAGE, senf::log::MESSAGE ); class Froblizer { // Define a new log area SENF_LOG_DEF_AREA(FroblizerArea); // Set default log parameters for this scope SENF_LOG_DEFAULTS((senf::log::Debug)(senf::log::NOTICE)(FroblizerArea)); // Define an alias for emergency messages to the sysadmin. // The log area is inherited from the default at the place, where this // alias is used *not* where it is defined SENF_LOG_DEF_ALIAS(LogEmerg, (userLog)(senf::log::CRITICAL)); void test(); public: void froblize(); }; void Froblizer::froblize() { SENF_LOG(("This is the Debug stream at level NOTICE in the FroblizeArea")); SENF_LOG((senf::log::WARNING) ("Same stream and area but at warning level")); SENF_LOG((LogEmerg) ("This goes to the userLog at level CRITICAL in the FroblizerArea")); } void Froblizer::test() { // Change the default log level for this method. stream and area are taken // from the next scope up SENF_LOG_DEFAULTS((senf::log::VERBOSE)); SENF_LOG(("Log to Debug stream in Froblizer area however at VERBOSE level")); } \endcode Currently, the library is not implemented in any way. The interface has been defined up to a point and we have dummy implementations of the 'in-code' part of the interface. This is the part, which is called throughout the code. The configuration API is defined but we don't even have a template implementation. However, this allows starting to use the SENF Logger in newly developed code. Even though this code will unconditionally log everything to \c std::cerr for now and errors in the parameter specification will not be caught (since they are just ignored) the logging should work automatically as advertised as soon as the logger is completely implemented. I did not find any implementation which was not either completely convoluted, unusable or slow. So I turned to a macro based implementation which can provide all the design goals stated above. \section logger_compile_conf Compile time configuration The logger infrastructure allows to enable or disable log levels or areas at compile time. Levels or areas disabled at compile time do not generate any code. The compile time configuration is done in two parts: When defining log streams, default log levels and log level limits are defined. Additionally the \c SENF_LOG_CONF symbol can be defined to customize this default configuration. The \c SENF_LOG_CONF symbol is a Boost.Preprocessor style sequence of sequences:
    g++ ... -DSENF_LOG_CONF="((senf::log::Debug)(_)(DISABLED)) \
                             ((senf::log::Debug)(foo::FooArea)(VERBOSE))" ...
    
Each element defines the compile time limit for a stream and optional area. \implementation I would have much preferred a more C++ like implementation. However given the design goals \li Flexible configuration at compile and runtime \li Concise usage and simple interface \li Zero overhead for compile-time disabled log messages */ // 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" // mode: flyspell // mode: auto-fill // End: