00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #ifndef HH_SENF_Utils_Logger_SyslogUDPTarget_
00027 #define HH_SENF_Utils_Logger_SyslogUDPTarget_ 1
00028
00029
00030 #include <syslog.h>
00031 #include "LogFormat.hh"
00032 #include "Target.hh"
00033 #include <senf/Socket/Protocols/INet/INetAddressing.hh>
00034 #include <senf/Socket/ClientSocketHandle.hh>
00035 #include <senf/Socket/FramingPolicy.hh>
00036 #include <senf/Socket/ReadWritePolicy.hh>
00037 #include <senf/Socket/CommunicationPolicy.hh>
00038
00039
00040
00041
00042 namespace senf {
00043 namespace log {
00044
00093 class SyslogUDPTarget
00094 : public Target, private detail::LogFormat
00095 {
00096 public:
00097
00098
00099
00100
00102
00103
00104 explicit SyslogUDPTarget(INet4Address const & target, int facility = LOG_USER);
00105 explicit SyslogUDPTarget(INet4SocketAddress const & target, int facility = LOG_USER);
00106 explicit SyslogUDPTarget(INet6Address const & target, int facility = LOG_USER);
00107 explicit SyslogUDPTarget(INet6SocketAddress const & target, int facility = LOG_USER);
00108
00109
00110
00111
00112 using detail::LogFormat::showTime;
00113 using detail::LogFormat::showStream;
00114 using detail::LogFormat::showLevel;
00115 using detail::LogFormat::showArea;
00116 using detail::LogFormat::timeFormat;
00117 using detail::LogFormat::tag;
00118
00119 bool syslog() const;
00120
00123 void syslog(bool enabled=true);
00124
00125 private:
00126 void init();
00127 void v_write(time_type timestamp, std::string const & stream,
00128 std::string const & area, unsigned level,
00129 std::string const & message);
00130
00131 void consoleFormat(std::ostream & os);
00132
00133 int facility_;
00134 typedef senf::ClientSocketHandle< senf::MakeSocketPolicy<
00135 senf::DatagramFramingPolicy,
00136 senf::ConnectedCommunicationPolicy,
00137 senf::WriteablePolicy>::policy > Handle;
00138 Handle handle_;
00139 bool syslogFormat_;
00140
00141 public:
00142 enum LogFacility {
00143 AUTHPRIV = LOG_AUTHPRIV,
00144 CRON = LOG_CRON,
00145 DAEMON = LOG_DAEMON,
00146 FTP = LOG_FTP,
00147 KERN = LOG_KERN,
00148 LOCAL0 = LOG_LOCAL0,
00149 LOCAL1 = LOG_LOCAL1,
00150 LOCAL2 = LOG_LOCAL2,
00151 LOCAL3 = LOG_LOCAL3,
00152 LOCAL4 = LOG_LOCAL4,
00153 LOCAL5 = LOG_LOCAL5,
00154 LOCAL6 = LOG_LOCAL6,
00155 LOCAL7 = LOG_LOCAL7,
00156 LPR = LOG_LPR,
00157 MAIL = LOG_MAIL,
00158 NEWS = LOG_NEWS,
00159 SYSLOG = LOG_SYSLOG,
00160 USER = LOG_USER,
00161 UUCP = LOG_UUCP
00162 };
00163
00164 private:
00165
00166 struct RegisterConsole {
00167 RegisterConsole();
00168 static boost::shared_ptr<console::DirectoryNode> create(
00169 INet4SocketAddress const & target, LogFacility facility = USER);
00170 static boost::shared_ptr<console::DirectoryNode> create(
00171 INet4Address const & target, LogFacility facility = USER);
00172 static boost::shared_ptr<console::DirectoryNode> create(
00173 INet6SocketAddress const & target, LogFacility facility = USER);
00174 static boost::shared_ptr<console::DirectoryNode> create(
00175 INet6Address const & target, LogFacility facility = USER);
00176 static RegisterConsole instance;
00177 };
00178 };
00179
00180 }}
00181
00182
00183 #include "SyslogUDPTarget.cci"
00184
00185
00186 #endif
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197