Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Class syslog_backend

boost::log::sinks::syslog_backend — An implementation of a syslog sink backend.

Synopsis

// In header: <boost/log/sinks/syslog_backend.hpp>


class syslog_backend : public basic_formatted_sink_backend< char > {
public:
  // types
  typedef base_type::char_type   char_type;             // Character type. 
  typedef base_type::string_type string_type;           // String type that is used to pass message test. 
  typedef unspecified            severity_mapper_type;  // Syslog severity level mapper type. 

  // construct/copy/destruct
  syslog_backend();
  template<typename... ArgsT> explicit syslog_backend(ArgsT...const &);
  ~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);
  void consume(record_view const &, string_type const &);
};

Description

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.

syslog_backend public construct/copy/destruct

  1. syslog_backend();

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

  2. template<typename... ArgsT> explicit 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.

    • ident - Process identification string. This parameter is only supported by native syslog implementation.

  3. ~syslog_backend();

    Destructor

syslog_backend public member functions

  1. void set_severity_mapper(severity_mapper_type const & mapper);

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

  2. 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] Note

    Does not have effect if the backend was constructed to use native syslog API

    Parameters:

    addr

    The local address

    port

    The local port number

  3. 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] Note

    Does not have effect if the backend was constructed to use native syslog API

    Parameters:

    addr

    The local address

    port

    The local port number

  4. 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] Note

    Does not have effect if the backend was constructed to use native syslog API

    Parameters:

    addr

    The remote host address

    port

    The port number on the remote host

  5. 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] Note

    Does not have effect if the backend was constructed to use native syslog API

    Parameters:

    addr

    The remote host address

    port

    The port number on the remote host

  6. 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


PrevUpHomeNext