X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FLogger%2FTarget.hh;h=b4137d6db827249696c1a8c78460d8bcb4d74f80;hb=ac86c2bb40746fbedf70a19af3307e5da642b04a;hp=24b6ea3cd7a852baf15d25f4009323fcdc5a85e2;hpb=394a298567543441521439ad15f7016cd569c449;p=senf.git diff --git a/Utils/Logger/Target.hh b/Utils/Logger/Target.hh index 24b6ea3..b4137d6 100644 --- a/Utils/Logger/Target.hh +++ b/Utils/Logger/Target.hh @@ -30,6 +30,7 @@ #include #include #include +#include #include "../singleton.hh" #include "../mpl.hh" #include "StreamRegistry.hh" @@ -60,6 +61,36 @@ namespace log { /////////////////////////////////////////////////////////////////////////// // Types + enum action_t { ACCEPT, REJECT }; + + struct RoutingEntry + { + RoutingEntry(); + bool operator==(RoutingEntry const & other); + + std::string stream() const; + std::string area() const; + unsigned level() const; + action_t action() const; + + private: + RoutingEntry(detail::StreamBase const * stream, detail::AreaBase const * area, + unsigned level, action_t action); + + detail::StreamBase const * stream_; + detail::AreaBase const * area_; + unsigned level_; + action_t action_; + + friend class Target; + }; + + private: + typedef std::vector RIB; + + public: + typedef RIB::const_iterator iterator; + /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members ///@{ @@ -69,34 +100,77 @@ namespace log { ///@} - template - void route(); - - template - void route(); - - template - void route(); - - protected: - - std::string timestamp(); + 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); + + void route(std::string const & stream, std::string const & area = "", + unsigned level = NONE::value, action_t action = ACCEPT, int index = -1); + + 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); + + void unroute(std::string const & stream, std::string const & area = "", + unsigned level = NONE::value, action_t action = ACCEPT); + void unroute(int index); + + 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"; } }; + iterator begin() const; + iterator end() const; + private: - void route(detail::StreamBase const * stream, detail::AreaBase const * area, - unsigned level); + unsigned level, action_t action, int index); void unroute(detail::StreamBase const * stream, detail::AreaBase const * area, - unsigned level); - - template - void route(detail::StreamBase const * stream, detail::AreaBase const *); - - template - void route(detail::StreamBase const * stream, detail::LevelBase const *); + unsigned level, action_t action); - void updateAreaCache(detail::AreaBase const & area, detail::StreamBase const * stream, - 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); @@ -113,27 +187,9 @@ namespace log { 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) {} - - bool operator==(RoutingEntry const & other) - { return stream == other.stream && area == other.area && level == other.level; } - - detail::StreamBase const * stream; - detail::AreaBase const * area; - unsigned level; - }; - - typedef std::vector RIB; - RIB rib_; - friend class TargetRegistry; + friend class detail::AreaBase; }; /** \brief Target registry