Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::sinks::syslog_backend Class Reference

An implementation of a syslog sink backend. More...

#include <syslog_backend.hpp>

Inheritance diagram for boost::sinks::syslog_backend:
Collaboration diagram for boost::sinks::syslog_backend:

Public Types

typedef base_type::char_type char_type
 Character type. More...
 
typedef base_type::string_type string_type
 String type that is used to pass message test. More...
 
typedef
boost::log::aux::light_function
< syslog::level(record_view
const &) > 
severity_mapper_type
 Syslog severity level mapper type. More...
 
typedef
base_type::frontend_requirements 
frontend_requirements
 Frontend requirements. More...
 

Public Member Functions

BOOST_LOG_API syslog_backend ()
 Constructor. More...
 
BOOST_LOG_API ~syslog_backend ()
 Constructor. More...
 
BOOST_LOG_API void set_severity_mapper (severity_mapper_type const &mapper)
 The method installs the function object that maps application severity levels to syslog levels. More...
 
BOOST_LOG_API void set_local_address (std::string const &addr, unsigned short port=514)
 The method sets the local host name which log records will be sent from. More...
 
BOOST_LOG_API void set_local_address (boost::asio::ip::address const &addr, unsigned short port=514)
 The method sets the local address which log records will be sent from. More...
 
BOOST_LOG_API void set_target_address (std::string const &addr, unsigned short port=514)
 The method sets the remote host name where log records will be sent to. More...
 
BOOST_LOG_API void set_target_address (boost::asio::ip::address const &addr, unsigned short port=514)
 The method sets the address of the remote host where log records will be sent to. More...
 
BOOST_LOG_API void consume (record_view const &rec, string_type const &formatted_message)
 The method passes the formatted message to the syslog API or sends to a syslog server. More...
 

Detailed Description

An implementation of a syslog sink backend.

The backend provides support for the syslog protocol, defined in RFC3164. The backend sends log records to a remote host via UDP. The host name can be specified by calling the set_target_address method. By default log records will be sent to localhost:514. The local address can be specified as well, by calling the set_local_address method. By default syslog packets will be sent from any local address available.

It is safe to create several sink backends with the same local addresses - the backends within the process will share the same socket. The same applies to different processes that use the syslog backends to send records from the same socket. However, it is not guaranteed to work if some third party facility is using the socket.

On systems with native syslog implementation it may be preferable to utilize the POSIX syslog API instead of direct socket management in order to bypass possible security limitations that may be in action. To do so one has to pass the use_impl = native to the backend constructor. Note, however, that in that case you will only have one chance to specify syslog facility and process identification string - on the first native syslog backend construction. Other native syslog backends will ignore these parameters. Obviously, the set_local_address and set_target_address methods have no effect for native backends. Using use_impl = native on platforms with no native support for POSIX syslog API will have no effect.

Member Typedef Documentation

Frontend requirements.

typedef boost::log::aux::light_function< syslog::level (record_view const&) > boost::sinks::syslog_backend::severity_mapper_type

Syslog severity level mapper type.

String type that is used to pass message test.

Constructor & Destructor Documentation

BOOST_LOG_API boost::sinks::syslog_backend::syslog_backend ( )

Constructor.

Creates a UDP socket-based backend with syslog::user facility code. IPv4 protocol will be used.

BOOST_LOG_API boost::sinks::syslog_backend::~syslog_backend ( )

Constructor.

Creates a sink backend with the specified named parameters. The following named parameters are supported:

  • facility - Specifies the facility code. If not specified, syslog::user will be used.
  • use_impl - Specifies the backend implementation. Can be one of:
  • native - Use the native syslog API, if available. If no native API is available, it is equivalent to udp_socket_based.
  • udp_socket_based - Use the UDP socket-based implementation, conforming to RFC3164 protocol specification. This is the default.
  • ip_version - Specifies IP protocol version to use, in case if socket-based implementation is used. Can be either v4 (the default one) or v6.
  • ident - Process identification string. This parameter is only supported by native syslog implementation.

Destructor

Member Function Documentation

BOOST_LOG_API void boost::sinks::syslog_backend::consume ( record_view const &  rec,
string_type const &  formatted_message 
)

The method passes the formatted message to the syslog API or sends to a syslog server.

BOOST_LOG_API void boost::sinks::syslog_backend::set_local_address ( std::string const &  addr,
unsigned short  port = 514 
)

The method sets the local host name which log records will be sent from.

The host name is resolved to obtain the final IP address.

Note
Does not have effect if the backend was constructed to use native syslog API
Parameters
addrThe local address
portThe local port number
BOOST_LOG_API void boost::sinks::syslog_backend::set_local_address ( boost::asio::ip::address const &  addr,
unsigned short  port = 514 
)

The method sets the local address which log records will be sent from.

Note
Does not have effect if the backend was constructed to use native syslog API
Parameters
addrThe local address
portThe local port number
BOOST_LOG_API void boost::sinks::syslog_backend::set_severity_mapper ( severity_mapper_type const &  mapper)

The method installs the function object that maps application severity levels to syslog levels.

BOOST_LOG_API void boost::sinks::syslog_backend::set_target_address ( std::string const &  addr,
unsigned short  port = 514 
)

The method sets the remote host name where log records will be sent to.

The host name is resolved to obtain the final IP address.

Note
Does not have effect if the backend was constructed to use native syslog API
Parameters
addrThe remote host address
portThe port number on the remote host
BOOST_LOG_API void boost::sinks::syslog_backend::set_target_address ( boost::asio::ip::address const &  addr,
unsigned short  port = 514 
)

The method sets the address of the remote host where log records will be sent to.

Note
Does not have effect if the backend was constructed to use native syslog API
Parameters
addrThe remote host address
portThe port number on the remote host

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