X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FLogger%2FTarget.hh;h=7c999b8ce64122c416a5ef099baa9cb3ddf05293;hb=e7aa3355bca498de96d75d441865216706e74e3f;hp=02226ca8901fee320d907e72b9b02b9aed20e503;hpb=012a592d56be453719b7fbba492b56ae804c048f;p=senf.git diff --git a/Utils/Logger/Target.hh b/Utils/Logger/Target.hh index 02226ca..7c999b8 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 @@ -35,6 +35,7 @@ #include "../mpl.hh" #include "StreamRegistry.hh" #include "AreaRegistry.hh" +#include "../Exception.hh" //#include "Target.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -51,12 +52,12 @@ namespace senf { namespace log { - - class TargetRegistry; + + namespace detail { class TargetRegistry; } /** \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 @@ -97,10 +98,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 +115,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 { @@ -208,9 +206,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 mandatory stream to match + \tparam Area optional area to match + \tparam Level optional 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 @@ -257,9 +255,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 mandatory stream to match + \tparam Area optional area to match + \tparam Level optional level, matches messages with at least the given level. \param[in] action routing action to take */ @@ -344,14 +342,14 @@ namespace log { ///\} /** \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 @@ -376,9 +374,9 @@ namespace log { 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 + 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 @@ -386,7 +384,7 @@ namespace log { 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 @@ -399,8 +397,58 @@ namespace log { RIB rib_; friend class detail::AreaBase; + friend class detail::TargetRegistry; + }; + + /** \brief Log message time source abstract base class + + Instances derived from TimeSource provide the Logging library with the current date/time + value. The \c operator() member must be implemented to return the current universal time + (UTC). + + A new TimeSource may be installed using \ref senf::log::timeSource(). + + \ingroup config + */ + struct TimeSource + { + virtual ~TimeSource(); + virtual boost::posix_time::ptime operator()() const = 0; + }; + + /** \brief Default %log message time source + + This time source is installed by default and uses gettimeofday() (via the Boost.DateTime + library) to get the current universal time. + + \ingroup config + */ + struct SystemTimeSource : public TimeSource + { + virtual boost::posix_time::ptime operator()() const; }; + /** \brief Change %log message time source + + Set the %log message time source to \a source. The logging library will take ownership of \e + source and will take care to free it, if necessary. + + Since the time source class will in almost all cases be default constructible, see the + template overload for a simpler interface. + + \ingroup config + */ + void timeSource(std::auto_ptr source); + + /** \brief Change %log message time source + + Set the %log message time source to (an instance of) \a Source. \a Source must be default + constructible, otherwise use the non-template senf::log::timeSource() overload. + + \ingroup config + */ + template void timeSource(); + }} ///////////////////////////////hh.e////////////////////////////////////////