Packets: Fix VariantParser invalid parser access bug
[senf.git] / Utils / Logger / Target.hh
index 664f5b2..2190ed5 100644 (file)
 /** \file
     \brief Target public header */
 
-#ifndef HH_Target_
-#define HH_Target_ 1
+#ifndef HH_SENF_Utils_Logger_Target_
+#define HH_SENF_Utils_Logger_Target_ 1
 
 // Custom includes
 #include <set>
-#include <boost/date_time/posix_time/posix_time.hpp>
+#include <vector>
 #include <boost/utility.hpp>
 #include <boost/type_traits/is_convertible.hpp>
 #include "../singleton.hh"
 #include "../mpl.hh"
 #include "StreamRegistry.hh"
-#include "AreaRegistry.hh"
 #include "../Exception.hh"
+#include "TimeSource.hh"
 
 //#include "Target.mpp"
 ///////////////////////////////hh.p////////////////////////////////////////
@@ -54,11 +54,12 @@ namespace senf {
 namespace log {
     
     namespace detail { class TargetRegistry; }
+    namespace detail { class AreaBase; }
 
     /** \brief Logging target base class
         
-        Targets are the final destination of %log messages. Every message is eventually routed to one
-        or several targets.
+        Targets are the final destination of %log messages. Every message is eventually routed to
+        one or several targets.
 
         \section target_routing Routing
 
@@ -66,12 +67,13 @@ namespace log {
         matched against this table. If an entry matches, the action associated with this entry is
         taken (either \c ACCEPT or \c REJECT).
 
-        Every target manages it's own routing table. Conceptually, every routing message will be
-        routed to every target where it will then be matched against each targets routing table (the
+        Every target manages it's own routing table. Conceptually, every message will be routed to
+        every target where it will then be matched against each targets routing table (the
         implementation is more efficient and utilizes a routing cache).
 
         Each routing entry consists of the following parameters
-        \li (optional) \e stream. The entry will match only messages directed at that stream
+        \li (optional) \e stream. If specified, the entry will match only messages directed at that
+            stream
         \li (optional) \e area. If the area is specified, only messages directed at that area are
             matched, otherwise any area will be allowed
         \li (optional) \e level. If the log level is specified, messages will be accepted if their
@@ -86,11 +88,13 @@ namespace log {
         \code
         target.route<foo::SomeStream, senf::log::NOTICE>(senf::log::Target::REJECT);
         target.route<foo::SomeStream>();
+        target.route();
         \endcode
         The identical routing statements may be expressed using dynamic routing via:
         \code
         target.route("foo::SomeStream", "", senf::log::NOTICE::value, senf::log::Target::REJECT);
         target.route("foo::SomeStream");
+        target.route();
         \endcode
         The static representation has the benefit of being compile-time type checked: Invalid
         routing parameters will be caught while compiling the code. The dynamic representation is
@@ -113,11 +117,11 @@ namespace log {
         To implement a new target type, you need to derive from senf::log::Target and implement the
         single \c v_write member. This member will be called whenever a message should be output. 
 
-        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
-        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.
+        The target may process the message in any arbitrary way: reformat it, write it into an SQL
+        DB, whatever can be envisioned. However, there is one important limitation: The \c v_write
+        call must \e not 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
       */
@@ -195,12 +199,15 @@ namespace log {
                                         /**< Add a route for the given combination of \a Stream, \a
                                              Area and \a Level. All parameters (\a Stream, \a Area
                                              and \a Level) are optional (the template signature is
-                                             shown simplified here). Examples:
+                                             shown simplified here). So possible commands are:
                                              \code
-                                             target.route<SomeLevel>();
+                                             target.route();
                                              target.route<SomeStream>();
-                                             target.route<SomeStream, SomeLevel>();
+                                             target.route<SomeArea>();
+                                             target.route<SomeLevel>();
                                              target.route<SomeStream, SomeArea>();
+                                             target.route<SomeStream, SomeLevel>();
+                                             target.route<SomeArea, SomeLevel>();
                                              target.route<SomeStream, SomeArea, SomeLevel>();
                                              \endcode
 
@@ -292,6 +299,7 @@ namespace log {
 
 #       ifndef DOXYGEN
 
+        void route(action_t action = ACCEPT, int index = -1);
         template <class A1>
         void route(action_t action = ACCEPT, int index = -1);
         template <class A1, class A2>
@@ -299,6 +307,7 @@ namespace log {
         template <class A1, class A2, class A3>
         void route(action_t action = ACCEPT, int index = -1);
 
+        void unroute(action_t action = ACCEPT);
         template <class A1>
         void unroute(action_t action = ACCEPT);
         template <class A1, class A2>
@@ -331,14 +340,14 @@ namespace log {
 
         void updateRoutingCache(detail::StreamBase const * stream, detail::AreaBase const * area);
 
-        void write(boost::posix_time::ptime timestamp, detail::StreamBase const & stream,
+        void write(time_type 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 timestamp, std::string const & stream, 
+        virtual void v_write(time_type timestamp, std::string const & stream, 
                              std::string const & area, unsigned level, 
                              std::string const & message) = 0;
                                         ///< Called to write out the routing message
@@ -369,55 +378,6 @@ namespace log {
         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<TimeSource> 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 <class Source> void timeSource();
-
 }}
 
 ///////////////////////////////hh.e////////////////////////////////////////