senf::log::SyslogUDPTarget Class Reference

Log target writing UDP syslog packets. More...

#include <senf/Utils/Logger/SyslogUDPTarget.hh>

Inheritance diagram for senf::log::SyslogUDPTarget:

Public Types

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
}
 
- Public Types inherited from senf::log::Target
enum  action_t { ACCEPT, REJECT }
 Routing action. More...
 
typedef RIB::const_iterator iterator
 Routing table iterator. More...
 
typedef RIB::size_type size_type
 

Public Member Functions

bool syslog () const
 true, if using syslog format, false otherwise More...
 
void syslog (bool enabled=true)
 Set syslog format. More...
 
- Public Member Functions inherited from senf::log::Target
iterator begin () const
 Iterator to beginning of routing table. More...
 
iterator end () const
 Iterator past the end of routing table. More...
 
RoutingEntry const & operator[] (size_type i) const
 Access routing entry. More...
 
size_type size () const
 Number of routing table entries. More...
 
bool empty () const
 true, if routing table empty, false otherwise More...
 
void flush ()
 Clear routing table. More...
 
senf::console::ScopedDirectoryconsoleDir ()
 Get console/config directory. More...
 
 Target (std::string const &name)
 
virtual ~Target ()
 
template<class Stream , class Area , class Level >
void route (action_t action=ACCEPT, int index=-1)
 Add route (static) More...
 
void route (std::string const &stream, std::string const &area="", unsigned level=NONE::value, action_t action=ACCEPT, int index=-1)
 Add route (dynamic) More...
 
template<class Stream , class Area , class Level >
void unroute (action_t action=ACCEPT)
 Remove route (static) More...
 
void unroute (std::string const &stream, std::string const &area="", unsigned level=NONE::value, action_t action=ACCEPT)
 Remove route (dynamic) More...
 
void unroute (int index=-1)
 Remove route (indexed) More...
 

Structors and default members

 SyslogUDPTarget (INet4Address const &target, int facility=LOG_USER)
 
 SyslogUDPTarget (INet4SocketAddress const &target, int facility=LOG_USER)
 
 SyslogUDPTarget (INet6Address const &target, int facility=LOG_USER)
 
 SyslogUDPTarget (INet6SocketAddress const &target, int facility=LOG_USER)
 

Additional Inherited Members

Detailed Description

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 RFC-3164.

This log target has some important benefits:

  • It will never block. It may however lose log messages.
  • It does not add timestamp information locally.

These are advantages since this makes SyslogUDPTarget a very reliable high-performance logging target.

Valid facility values are from man 3 syslog:

LOG_AUTHPRIV, LOG_CRON, LOG_DAEMON, LOG_FTP, LOG_KERN, LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, LOG_LOCAL3, LOG_LOCAL4, LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7, LOG_LPR, LOG_MAIL, LOG_NEWS, LOG_SYSLOG, LOG_USER, LOG_UUCP

the default facility is LOG_USER

The SENF log levels are mapped to syslog levels in the following way:

senf::log::VERBOSE LOG_DEBUG
senf::log::NOTICE LOG_INFO
senf::log::MESSAGE LOG_NOTICE
senf::log::IMPORTANT LOG_WARNING
senf::log::CRITICAL LOG_CRIT
senf::log::FATAL LOG_EMERG
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 newline char since non-printable characters are not allowed.
Implementation note:
The RFC only recommends the exact message format. This allows us to include the PRI part but skip the HEADER part (which includes the timestamp and hostname) for better performance. We add a space after the PRI to force the syslog daemon to skip the HEADER part.

Definition at line 84 of file SyslogUDPTarget.hh.

Member Enumeration Documentation

◆ LogFacility

Enumerator
AUTHPRIV 
CRON 
DAEMON 
FTP 
KERN 
LOCAL0 
LOCAL1 
LOCAL2 
LOCAL3 
LOCAL4 
LOCAL5 
LOCAL6 
LOCAL7 
LPR 
MAIL 
NEWS 
SYSLOG 
USER 
UUCP 

Definition at line 133 of file SyslogUDPTarget.hh.

Constructor & Destructor Documentation

◆ SyslogUDPTarget() [1/4]

senf::log::SyslogUDPTarget::SyslogUDPTarget ( INet4Address const &  target,
int  facility = LOG_USER 
)
explicit

◆ SyslogUDPTarget() [2/4]

senf::log::SyslogUDPTarget::SyslogUDPTarget ( INet4SocketAddress const &  target,
int  facility = LOG_USER 
)
explicit

◆ SyslogUDPTarget() [3/4]

senf::log::SyslogUDPTarget::SyslogUDPTarget ( INet6Address const &  target,
int  facility = LOG_USER 
)
explicit

◆ SyslogUDPTarget() [4/4]

senf::log::SyslogUDPTarget::SyslogUDPTarget ( INet6SocketAddress const &  target,
int  facility = LOG_USER 
)
explicit

Member Function Documentation

◆ syslog() [1/2]

bool senf::log::SyslogUDPTarget::syslog ( ) const

true, if using syslog format, false otherwise

When syslog format is disabled, messages are not formatted as valid syslog messages but sent using plain UDP.

◆ syslog() [2/2]

void senf::log::SyslogUDPTarget::syslog ( bool  enabled = true)

Set syslog format.


The documentation for this class was generated from the following files: