X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FLogger%2FTarget.hh;h=ff8fc5467fe0cb7df75feed8c8805a9d14be373e;hb=456ee576285b76aa46240f8001f426757810dcc1;hp=5b8dd1b9ddb9a3dec3f4a94486c910bc22361df2;hpb=044a1bfb46ce16c3daac307b8c684604b43dd4cf;p=senf.git diff --git a/Utils/Logger/Target.hh b/Utils/Logger/Target.hh index 5b8dd1b..ff8fc54 100644 --- a/Utils/Logger/Target.hh +++ b/Utils/Logger/Target.hh @@ -1,8 +1,8 @@ // $Id$ // -// Copyright (C) 2007 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 @@ -28,13 +28,14 @@ // Custom includes #include -#include +#include #include #include #include "../singleton.hh" #include "../mpl.hh" #include "StreamRegistry.hh" -#include "AreaRegistry.hh" +#include "../Exception.hh" +#include "TimeSource.hh" //#include "Target.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -51,12 +52,13 @@ namespace senf { namespace log { - - class TargetRegistry; + + namespace detail { class TargetRegistry; } + namespace detail { class AreaBase; } /** \brief Logging target base class - Targets are the final destination of log messages. Every message is eventually routed to one + Targets are the final destination of %log messages. Every message is eventually routed to one or several targets. \section target_routing Routing @@ -70,7 +72,7 @@ namespace log { implementation is more efficient and utilizes a routing cache). Each routing entry consists of the following parameters - \li (mandatory) \e stream. The entry will match only messages directed at that stream + \li (optional) \e stream. The entry will match only messages directed at that stream \li (optional) \e area. If the area is specified, only messages directed at that area are matched, otherwise any area will be allowed \li (optional) \e level. If the log level is specified, messages will be accepted if their @@ -97,10 +99,10 @@ namespace log { The different object representations are: \li The \e streams is statically represented by it's name, which is the name of a class - defined with \ref SENF_LOG_DEF_STREAM. The dynamic representation is a string + defined with \ref SENF_LOG_DEFINE_STREAM. The dynamic representation is a string representation of this name. \li The \e area is statically represented by it's name, which again is the name of a class - defined with \ref SENF_LOG_DEF_STREAM. The dynamic representation again is a string + defined with \ref SENF_LOG_DEFINE_STREAM. The dynamic representation again is a string representation of this class's name. The dynamic representation represents an absent area with the empty string. \li The \e level is statically represented by a level class from \ref @@ -114,14 +116,11 @@ namespace log { The target may process in any arbitrary way: reformat, writing it into an SQL DB, whatever can be envisioned. However, there is one important limitation: The \c v_write call must not - block. So for more complex scenarios, additional measures must be taken (e.g. writing a log + block. So for more complex scenarios, additional measures must be taken (e.g. writing a %log backend daemon which receives the messages via UDP and processes them). Of course, in rare cases messages might be lost but this cannot be avoided. \see \ref targets - - \fixme optionally Integrate with Scheduler / ClockService to reduce number of gettimeofday() - calls. */ class Target : private boost::noncopyable { @@ -195,10 +194,11 @@ namespace log { template void route( action_t action = ACCEPT, int index = -1); ///< Add route (static) /**< Add a route for the given combination of \a Stream, \a - Area and \a Level. The \a Stream parameter is mandatory - while either \a Area or \a Level are optional (the - template signature is shown simplified here): + Area and \a Level. All parameters (\a Stream, \a Area + and \a Level) are optional (the template signature is + shown simplified here). Examples: \code + target.route(); target.route(); target.route(); target.route(); @@ -208,9 +208,9 @@ namespace log { See the class description for information on the \a action and \a index parameters - \param[in] Stream mandatory stream to match - \param[in] Area optional area to match - \param[in] Level optional level, matches messages with + \tparam Stream stream to match + \tparam Area area to match + \tparam Level level, matches messages with at least the given level. \param[in] action routing action to take \param[in] index position of new route in the routing @@ -222,9 +222,9 @@ namespace log { unsigned level = NONE::value, action_t action = ACCEPT, int index = -1); ///< Add route (dynamic) /**< Add a route for the given combination of \a stream, \a - area and \a level. The \a stream parameter is mandatory - while either \a area or \a level may be left - unspecified by setting them to the empty string or + area and \a level. All parameters (\a Stream, \a Area + and \a Level) are optional and may be omitted by + setting them to the empty string or the senf::log::NONE::value respectively. See the class description for information on the \a @@ -235,10 +235,10 @@ namespace log { \throws InvalidAreaException if the given \a area is not found in the AreaRegistry - \param[in] stream mandatory stream to match - \param[in] area optional area to match - \param[in] level optional level, matches messages with - at least the given level. + \param[in] stream stream to match + \param[in] area area to match + \param[in] level level, matches messages with at least + the given level. \param[in] action routing action to take \param[in] index position of new route in the routing table */ @@ -257,9 +257,9 @@ namespace log { found, it will be removed, otherwise the call will be ignored - \param[in] Stream mandatory stream to match - \param[in] Area optional area to match - \param[in] Level optional level, matches messages with + \tparam Stream stream to match + \tparam Area area to match + \tparam Level level, matches messages with at least the given level. \param[in] action routing action to take */ @@ -278,10 +278,10 @@ namespace log { found, it will be removed, otherwise the call will be ignored - \param[in] stream mandatory stream to match - \param[in] area optional area to match - \param[in] level optional level, matches messages with - at least the given level. + \param[in] stream stream to match + \param[in] area area to match + \param[in] level level, matches messages with at least + the given level. \param[in] action routing action to take */ void unroute(int index=-1); ///< Remove route (indexed) /**< This call will remove the route with the given index. @@ -293,65 +293,33 @@ namespace log { # ifndef DOXYGEN - template void route( - action_t action = ACCEPT, int index = -1); - template void route( - action_t action = ACCEPT, int index = -1, - typename boost::enable_if< boost::is_convertible >::type * = 0); - template void route( - action_t action = ACCEPT, int index = -1, - typename boost::enable_if< boost::is_convertible >::type * = 0); - template void route( - action_t action = ACCEPT, int index = -1, - typename boost::enable_if< boost::is_convertible >::type * = 0); - template void route( - action_t action = ACCEPT, int index = -1, - typename boost::enable_if< boost::is_convertible >::type * = 0); - template void route( - action_t action = ACCEPT, int index = -1, - typename boost::enable_if< boost::is_convertible >::type * = 0); - - template void unroute( - action_t action = ACCEPT); - template void unroute( - action_t action = ACCEPT, - typename boost::enable_if< boost::is_convertible >::type * = 0); - template void unroute( - action_t action = ACCEPT, - typename boost::enable_if< boost::is_convertible >::type * = 0); - template void unroute( - action_t action = ACCEPT, - typename boost::enable_if< boost::is_convertible >::type * = 0); - template void unroute( - action_t action = ACCEPT, - typename boost::enable_if< boost::is_convertible >::type * = 0); - template void unroute( - action_t action = ACCEPT, - typename boost::enable_if< boost::is_convertible >::type * = 0); + template + void route(action_t action = ACCEPT, int index = -1); + template + void route(action_t action = ACCEPT, int index = -1); + template + void route(action_t action = ACCEPT, int index = -1); + + template + void unroute(action_t action = ACCEPT); + template + void unroute(action_t action = ACCEPT); + template + void unroute(action_t action = ACCEPT); # endif ///\} /** \brief Exception: Invalid stream */ - struct InvalidStreamException : public std::exception - { virtual char const * what() const throw() - { return "senf::log::Target::InvalidStreamException"; } }; + struct InvalidStreamException : public senf::Exception + { InvalidStreamException() + : senf::Exception("senf::log::Target::InvalidStreamException"){} }; /** \brief Exception: Invalid area */ - struct InvalidAreaException : public std::exception - { virtual char const * what() const throw() - { return "senf::log::Target::InvalidAreaException"; } }; + struct InvalidAreaException : public senf::Exception + { InvalidAreaException() + : senf::Exception("senf::log::Target::InvalidAreaException"){} }; iterator begin() const; ///< Iterator to beginning of routing table iterator end() const; ///< Iterator past the end of routing table @@ -364,31 +332,29 @@ namespace log { void updateRoutingCache(detail::StreamBase const * stream, detail::AreaBase const * area); - void write(boost::posix_time::ptime timestamp, detail::StreamBase const & stream, + void write(time_type timestamp, detail::StreamBase const & stream, detail::AreaBase const & area, unsigned level, std::string const & message); # ifdef DOXYGEN protected: # endif - virtual void v_write(boost::posix_time::ptime timestamp, std::string const & stream, + virtual void v_write(time_type timestamp, std::string const & stream, std::string const & area, unsigned level, std::string const & message) = 0; ///< Called to write out the routing message /**< This member must be defined in the derived class to - somehow format and write the log message. + somehow format and write the %log message. - Every log message always possesses a complete set of - meta information (\a stream, \a area and \a level). The - \a area may be an empty string if the message was - written from the senf::log::DefaultArea. + Every %log message always possesses a complete set of + meta information (\a stream, \a area and \a level). \note This member must \e not block since it may be called from any unknown context. This prohibits simple logging over NFS or many other network protocols. - \param[in] timestamp log message timing information + \param[in] timestamp %log message timing information \param[in] stream message stream \param[in] area message area \param[in] level message level @@ -401,6 +367,7 @@ namespace log { RIB rib_; friend class detail::AreaBase; + friend class detail::TargetRegistry; }; }}