X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FLogger%2FTarget.hh;h=56cf519b877be646f7e8b2e65c0c728f1ffecc55;hb=f6f670f2dbc82b77db29df6cd452f2b351b9662a;hp=9a47194aec847b10869557a488240caf35ae34fc;hpb=ae06fe86f16fdabb7ffb219d255444d2eb4f4f79;p=senf.git diff --git a/Utils/Logger/Target.hh b/Utils/Logger/Target.hh index 9a47194..56cf519 100644 --- a/Utils/Logger/Target.hh +++ b/Utils/Logger/Target.hh @@ -50,6 +50,9 @@ 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 : private boost::noncopyable { @@ -57,6 +60,8 @@ namespace log { /////////////////////////////////////////////////////////////////////////// // Types + enum action_t { ACCEPT, REJECT }; + /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members ///@{ @@ -67,14 +72,28 @@ namespace log { ///@} template - void route(); + void route(action_t action=ACCEPT); - template - void route(); + template + void route(action_t action=ACCEPT); template - void route(); + 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(); @@ -82,18 +101,17 @@ namespace log { 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); template - void route(detail::StreamBase const * stream, detail::AreaBase const *); + void route(detail::StreamBase const * stream, detail::AreaBase const *, action_t action); template - void route(detail::StreamBase const * stream, detail::LevelBase const *); - - void updateAreaCache(detail::AreaBase const & area, detail::StreamBase const * stream, - unsigned level); + void route(detail::StreamBase const * stream, detail::LevelBase const *, action_t action); + + 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,24 +131,21 @@ namespace log { 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 TargetRegistry; + friend class detail::AreaBase; }; /** \brief Target registry