Sovite.Core.Logging.SyslogHandler (sovite v0.6.0)

Copy Markdown View Source

:logger handler that sends log lines to a syslog daemon: to a local socket such as /dev/log (journald, rsyslog, syslog-ng), or over UDP to a remote host.

Messages use the classic BSD format (RFC 3164) by default:

<22>Oct  4 12:00:00 sovite[812]: queue_id=4Xb2Kq event=queue.message.enqueued queue.message.enqueued: ...

with the host name added for remote daemons, or RFC 5424:

<22>1 2026-10-04T12:00:00.123456Z mx1 sovite 812 - - queue_id=4Xb2Kq ...

The tag is sovite, the facility mail unless configured, and the severity follows the log level. The message is the line of the text formatter without its date and level, or a JSON object with format: :json. Messages over 8 KiB are cut.

Sending never blocks: when the daemon is not running or cannot keep up, lines are dropped.

Run it under a supervisor, like Sovite.Core.Logging.FileHandler:

{Sovite.Core.Logging.SyslogHandler,
 id: :sovite_syslog,
 address: {:unix, "/dev/log"},
 facility: :mail,
 format: :rfc3164,
 formatter: Sovite.Core.Logging.formatter(:text)}

Options

  • :id - the :logger handler ID. Required.
  • :address - {:unix, path} or {:udp, host, port}. Required.
  • :formatter - the {module, config} formatter of the message. Required.
  • :facility - :mail, :daemon, :user, or :local0 to :local7. Defaults to :mail.
  • :format - :rfc3164 or :rfc5424. Defaults to :rfc3164.
  • :hostname - for remote daemons and RFC 5424. Defaults to the system's host name.
  • :replace - ID of a handler that is silenced (level :none) while this one runs.

Summary

Functions

Encodes one syslog message. time is a UTC DateTime; config has the :facility, :format, :hostname, :local (no host name in RFC 3164 messages to a local socket), :pid, and :utc (RFC 3164 times in UTC instead of local time) keys.

Opens the socket and installs the :logger handler.

Functions

encode(level, time, message, config)

@spec encode(:logger.level(), DateTime.t(), iodata(), map()) :: binary()

Encodes one syslog message. time is a UTC DateTime; config has the :facility, :format, :hostname, :local (no host name in RFC 3164 messages to a local socket), :pid, and :utc (RFC 3164 times in UTC instead of local time) keys.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Opens the socket and installs the :logger handler.