Method: Logging::Appenders::Syslog#initialize

Defined in:
lib/logging/appenders/syslog.rb

#initialize(name, opts = {}) ⇒ Syslog

call-seq:

Syslog.new( name, opts = {} )

Create an appender that will log messages to the system message logger. The message is then written to the system console, log files, logged-in users, or forwarded to other machines as appropriate. The options that can be used to configure the appender are as follows:

:ident     => identifier string (name is used by default)
:logopt    => options used when opening the connection
:facility  => the syslog facility to use

The parameter :ident is a string that will be prepended to every message. The :logopt argument is a bit field specifying logging options, which is formed by OR’ing one or more of the following values:

LOG_CONS      If syslog() cannot pass the message to syslogd(8) it
              wil attempt to write the message to the console
              ('/dev/console').

LOG_NDELAY    Open the connection to syslogd(8) immediately. Normally
              the open is delayed until the first message is logged.
              Useful for programs that need to manage the order in
              which file descriptors are allocated.

LOG_PERROR    Write the message to standard error output as well to
              the system log.  Not available on Solaris.

LOG_PID       Log the process id with each message: useful for
              identifying instantiations of daemons.

The :facility parameter encodes a default facility to be assigned to all messages that do not have an explicit facility encoded:

LOG_AUTH      The authorization system: (1), su(1), getty(8),
              etc.

LOG_AUTHPRIV  The same as LOG_AUTH, but logged to a file readable
              only by selected individuals.

LOG_CONSOLE   Messages written to /dev/console by the kernel console
              output driver.

LOG_CRON      The cron daemon: cron(8).

LOG_DAEMON    System daemons, such as routed(8), that are not
              provided for explicitly by other facilities.

LOG_FTP       The file transfer protocol daemons: ftpd(8), tftpd(8).

LOG_KERN      Messages generated by the kernel. These cannot be
              generated by any user processes.

LOG_LPR       The line printer spooling system: lpr(1), lpc(8),
              lpd(8), etc.

LOG_MAIL      The mail system.

LOG_NEWS      The network news system.

LOG_SECURITY  Security subsystems, such as ipfw(4).

LOG_SYSLOG    Messages generated internally by syslogd(8).

LOG_USER      Messages generated by random user processes. This is
              the default facility identifier if none is specified.

LOG_UUCP      The uucp system.

LOG_LOCAL0    Reserved for local use. Similarly for LOG_LOCAL1
              through LOG_LOCAL7.


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/logging/appenders/syslog.rb', line 95

def initialize( name, opts = {} )
  @ident = opts.fetch(:ident, name)
  @logopt = Integer(opts.fetch(:logopt, (LOG_PID | LOG_CONS)))
  @facility = Integer(opts.fetch(:facility, LOG_USER))
  @syslog = ::Syslog.open(@ident, @logopt, @facility)

  # provides a mapping from the default Logging levels
  # to the syslog levels
  @map = [LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERR, LOG_CRIT]

  map = opts.fetch(:map, nil)
  self.map = map unless map.nil?

  super
end