X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FLogger%2FTarget.hh;h=9a47194aec847b10869557a488240caf35ae34fc;hb=ae06fe86f16fdabb7ffb219d255444d2eb4f4f79;hp=43ae95449cdd2a640168eadb0955e96201a2a544;hpb=9ff976ea47b175355a1f7ef4d05f14edb98a82e4;p=senf.git diff --git a/Utils/Logger/Target.hh b/Utils/Logger/Target.hh index 43ae954..9a47194 100644 --- a/Utils/Logger/Target.hh +++ b/Utils/Logger/Target.hh @@ -27,9 +27,13 @@ #define HH_Target_ 1 // Custom includes +#include +#include +#include #include "../singleton.hh" -#include "Stream.hh" -#include "Area.hh" +#include "../mpl.hh" +#include "StreamRegistry.hh" +#include "AreaRegistry.hh" //#include "Target.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -37,10 +41,17 @@ namespace senf { namespace log { - /** \brief + class TargetRegistry; + + /** \brief Logging target base class + + All enabled log messages are eventually routed to one or more logging targets. It is the + responsibility of the logging target to write the log messages somewhere: onto the console, + 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). */ - class Target - : public senf::singleton + class Target : private boost::noncopyable { public: /////////////////////////////////////////////////////////////////////////// @@ -50,19 +61,24 @@ namespace log { ///\name Structors and default members ///@{ + Target(); virtual ~Target(); - // default default constructor - // default copy constructor - // default copy assignment - // default destructor + ///@} - // no conversion constructors + template + void route(); - ///@} + template + void route(); + + template + void route(); protected: + std::string timestamp(); + private: void route(detail::StreamBase const * stream, detail::AreaBase const * area, @@ -70,15 +86,30 @@ namespace log { 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 *); + void updateAreaCache(detail::AreaBase const & area, detail::StreamBase const * stream, unsigned level); - void write(detail::StreamBase const & stream, detail::AreaBase const & area, - unsigned level, std::string const & message); - - virtual void v_write(std::string const & stream, std::string const & area, unsigned level, + 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_, @@ -98,14 +129,43 @@ namespace log { typedef std::vector RIB; RIB rib_; + + friend class TargetRegistry; + }; + + /** \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