boost::log::sinks::basic_syslog_backend — An implementation of a syslog sink backend.
// In header: <boost/log/sinks/syslog_backend.hpp> template<typename CharT> class basic_syslog_backend : public basic_formatting_sink_backend< CharT, char > { public: // types typedef base_type::char_type char_type; // Character type. typedef base_type::string_type string_type; // String type. typedef base_type::target_string_type target_string_type; // String type that is used to pass message test. typedef base_type::values_view_type values_view_type; // Attribute values view type. typedef base_type::record_type record_type; // Log record type. typedef boost::function1< syslog::level_t, values_view_type const & > severity_mapper_type; // Syslog severity level mapper type. // construct/copy/destruct basic_syslog_backend(); template<typename... ArgsT> explicit basic_syslog_backend(ArgsT...const &); ~basic_syslog_backend(); // public member functions void set_severity_mapper(severity_mapper_type const &); void set_local_address(std::string const &, unsigned short = 514); void set_local_address(boost::asio::ip::address const &, unsigned short = 514); void set_target_address(std::string const &, unsigned short = 514); void set_target_address(boost::asio::ip::address const &, unsigned short = 514); };
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 - on the first native syslog backend construction. Other native syslog backends will ignore this parameter. 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.
basic_syslog_backend
public
construct/copy/destructbasic_syslog_backend();
Constructor. Creates a UDP socket-based backend with syslog::user
facility code. IPv4 protocol will be used.
template<typename... ArgsT> explicit basic_syslog_backend(ArgsT...const & args);
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
.
~basic_syslog_backend();
Destructor
basic_syslog_backend
public member functionsvoid set_severity_mapper(severity_mapper_type const & mapper);
The method installs the function object that maps application severity levels to syslog levels
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. 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: |
|
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.
Note | |
---|---|
Does not have effect if the backend was constructed to use native syslog API |
Parameters: |
|
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. 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: |
|
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.
Note | |
---|---|
Does not have effect if the backend was constructed to use native syslog API |
Parameters: |
|