X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FLogger%2FTarget.hh;h=56cf519b877be646f7e8b2e65c0c728f1ffecc55;hb=f6f670f2dbc82b77db29df6cd452f2b351b9662a;hp=6298800532f49b7ef3e6714dd4db26c058b5b14c;hpb=61419d9a2e1060f7ede22fa19fd9d0b401bbc87a;p=senf.git diff --git a/Utils/Logger/Target.hh b/Utils/Logger/Target.hh index 6298800..56cf519 100644 --- a/Utils/Logger/Target.hh +++ b/Utils/Logger/Target.hh @@ -27,7 +27,11 @@ #define HH_Target_ 1 // Custom includes +#include +#include +#include #include "../singleton.hh" +#include "../mpl.hh" #include "StreamRegistry.hh" #include "AreaRegistry.hh" @@ -37,6 +41,8 @@ namespace senf { namespace log { + class TargetRegistry; + /** \brief Logging target base class All enabled log messages are eventually routed to one or more logging targets. It is the @@ -44,74 +50,137 @@ namespace log { to a file, to mail them to the administrator or whatever. To this end, the logging target is passed the log message and a complete set of logging parameters (\e stream, \e area and \e level). + + \fixme optionally Integrate with Scheduler / ClockService to reduce number of gettimeofday() + calls. */ - class Target - : public senf::singleton + class Target : private boost::noncopyable { public: /////////////////////////////////////////////////////////////////////////// // Types + enum action_t { ACCEPT, REJECT }; + /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members ///@{ + Target(); virtual ~Target(); - // default default constructor - // default copy constructor - // default copy assignment - // default destructor + ///@} + + template + void route(action_t action=ACCEPT); - // no conversion constructors + template + void route(action_t action=ACCEPT); - ///@} + template + void route(action_t action=ACCEPT); + + void route(std::string const & stream, action_t action=ACCEPT); + void route(std::string const & stream, std::string const & area, action_t action=ACCEPT); + void route(std::string const & stream, unsigned level, action_t action=ACCEPT); + void route(std::string const & stream, std::string const & area, unsigned level, + action_t action=ACCEPT); + + struct InvalidStreamException : public std::exception + { virtual char const * what() const throw() + { return "senf::log::Target::InvalidStreamException"; } }; + struct InvalidAreaException : public std::exception + { virtual char const * what() const throw() + { return "senf::log::Target::InvalidAreaException"; } }; + protected: + std::string timestamp(); + private: void route(detail::StreamBase const * stream, detail::AreaBase const * area, - unsigned level); + unsigned level, action_t action); void unroute(detail::StreamBase const * stream, detail::AreaBase const * area, - unsigned level); + unsigned level, action_t action); - void updateAreaCache(detail::AreaBase const & area, detail::StreamBase const * stream, - unsigned level); + template + void route(detail::StreamBase const * stream, detail::AreaBase const *, action_t action); - void write(detail::StreamBase const & stream, detail::AreaBase const & area, - unsigned level, std::string const & message); + template + void route(detail::StreamBase const * stream, detail::LevelBase const *, action_t action); - virtual void v_write(std::string const & stream, std::string const & area, unsigned level, + void updateRoutingCache(detail::StreamBase const * stream, detail::AreaBase const * area); + + void write(boost::posix_time::ptime 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, std::string const & stream, + std::string const & area, unsigned level, std::string const & message) = 0; +# ifdef DOXYGEN + private: +# endif + struct RoutingEntry { RoutingEntry(detail::StreamBase const * stream_, detail::AreaBase const * area_, - unsigned level_) - : stream(stream_), area(area_), level(level_) {} - RoutingEntry() - : stream(0), area(0), level(0) {} + unsigned level_, action_t action_); + RoutingEntry(); - bool operator==(RoutingEntry const & other) - { return stream == other.stream && area == other.area && level == other.level; } + bool operator==(RoutingEntry const & other); detail::StreamBase const * stream; detail::AreaBase const * area; - unsigned level; + unsigned level; action_t action; }; typedef std::vector RIB; RIB rib_; + + friend class detail::AreaBase; }; + /** \brief Target registry + + The TargetRegistry keeps a record of all existing targets. + */ + class TargetRegistry + : public senf::singleton + { + public: + using senf::singleton::instance; + + void write(detail::StreamBase const & stream, detail::AreaBase const & area, + unsigned level, std::string msg); + + private: + void registerTarget(Target * target); + void unregisterTarget(Target * target); + + typedef std::set Targets; + Targets targets_; + + friend class Target; + }; + + + template + void write(std::string msg); + }} ///////////////////////////////hh.e//////////////////////////////////////// #include "Target.cci" //#include "Target.ct" -//#include "Target.cti" +#include "Target.cti" #endif