Socket/Protocols/Raw: EUI64 documentation
[senf.git] / Utils / Logger / SyslogUDPTarget.hh
index a025c3e..71732d5 100644 (file)
@@ -28,6 +28,7 @@
 
 // Custom includes
 #include "SyslogTarget.hh"
+#include "LogFormat.hh"
 #include "../../Socket/Protocols/INet/INetAddressing.hh"
 #include "../../Socket/ClientSocketHandle.hh"
 #include "../../Socket/FramingPolicy.hh"
@@ -42,9 +43,9 @@ namespace log {
 
     /** \brief Log target writing UDP syslog packets
 
-        The SyslogUDPTarget will send all log messages directly via UDP to a target host. This host
-        should have a syslog daemon or relay running. The protocol is defined in <a
-        href="ttp://tools.ietf.org/html/rfc3164">RFC-3164</a>.
+        The SyslogUDPTarget will send all %log messages directly via UDP to a target host. This 
+        host should have a syslog daemon or relay running. The protocol is defined in <a
+        href="http://tools.ietf.org/html/rfc3164">RFC-3164</a>.
 
         This log target has some important benefits:
 
@@ -65,7 +66,7 @@ namespace log {
 
         the default facility is <tt>LOG_USER</tt>
 
-        The SENF log levels are mapped to syslog levels in the following way:
+        The SENF %log levels are mapped to syslog levels in the following way:
 
         <table class="senf fixedcolumn">
         <tr><td>senf::log::VERBOSE</td>   <td>\c LOG_DEBUG</td></tr>
@@ -77,12 +78,19 @@ namespace log {
         </table>
 
         \note Since the UDP syslog packets are limited to 1024 characters and there must be some
-            space left so a relay may optionally add a timestamp and hostname section, the log
-            messages are split after 896 characters. Additionally the log messages are split at each
+            space left so a relay may optionally add a timestamp and hostname section, the %log
+            messages are split after 896 characters. Additionally the %log messages are split at each
             newline char since non-printable characters are not allowed.
+
+        \implementation The RFC only \e recommends the exact message format. This allows us to
+            include the \c PRI part but skip the \c HEADER part (which includes the timestamp and
+            hostname) for better performance. We add a space after the \c PRI to force the syslog
+            daemon to skip the \c HEADER part.
+
+        \ingroup targets
      */
     class SyslogUDPTarget
-        : public Target
+        : public Target, private detail::LogFormat
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -100,23 +108,78 @@ namespace log {
         ///@}
         ///////////////////////////////////////////////////////////////////////////
 
+        using detail::LogFormat::showTime;
+        using detail::LogFormat::showStream;
+        using detail::LogFormat::showLevel;
+        using detail::LogFormat::showArea;
+        using detail::LogFormat::timeFormat;
+        using detail::LogFormat::tag;
+
+        bool syslog() const;            ///< \c true, if using syslog format, \c false otherwise
+                                        /**< When syslog format is disabled, messages are not
+                                             formated as valid syslog messages but sent using plain
+                                             UDP. */
+        void syslog(bool enabled=true); ///< Set syslog format
+
     private:
+        void init(); 
         void v_write(time_type timestamp, std::string const & stream, 
                      std::string const & area, unsigned level, 
                      std::string const & message);
 
+        void consoleFormat(std::ostream & os);
+
         int facility_;
         typedef senf::ClientSocketHandle< senf::MakeSocketPolicy<
             senf::DatagramFramingPolicy,
             senf::ConnectedCommunicationPolicy,
             senf::WriteablePolicy>::policy > Handle;
         Handle handle_;
+        bool syslogFormat_;
+
+    public:
+        enum LogFacility { 
+            AUTHPRIV = LOG_AUTHPRIV,
+            CRON = LOG_CRON,
+            DAEMON = LOG_DAEMON,
+            FTP = LOG_FTP,
+            KERN = LOG_KERN,
+            LOCAL0 = LOG_LOCAL0,
+            LOCAL1 = LOG_LOCAL1,
+            LOCAL2 = LOG_LOCAL2,
+            LOCAL3 = LOG_LOCAL3,
+            LOCAL4 = LOG_LOCAL4,
+            LOCAL5 = LOG_LOCAL5,
+            LOCAL6 = LOG_LOCAL6,
+            LOCAL7 = LOG_LOCAL7,
+            LPR = LOG_LPR,
+            MAIL = LOG_MAIL,
+            NEWS = LOG_NEWS,
+            SYSLOG = LOG_SYSLOG,
+            USER = LOG_USER,
+            UUCP = LOG_UUCP
+        };
+
+    private:
+
+        struct RegisterConsole {
+            RegisterConsole();
+            static boost::shared_ptr<senf::console::DirectoryNode> create(
+                senf::INet4SocketAddress const & target, LogFacility facility = USER);
+            static boost::shared_ptr<senf::console::DirectoryNode> create(
+                senf::INet4Address const & target, LogFacility facility = USER);
+            static boost::shared_ptr<senf::console::DirectoryNode> create(
+                senf::INet6SocketAddress const & target, LogFacility facility = USER);
+            static boost::shared_ptr<senf::console::DirectoryNode> create(
+                senf::INet6Address const & target, LogFacility facility = USER);
+            static RegisterConsole instance;
+        };
     };
 
 }}
 
 ///////////////////////////////hh.e////////////////////////////////////////
-//#include "SyslogUDPTarget.cci"
+#include "SyslogUDPTarget.cci"
 //#include "SyslogUDPTarget.ct"
 //#include "SyslogUDPTarget.cti"
 #endif