Syslog is an Elixir port of the erlang Twig logger. It is an Elixir logger backend providing UDP support to a syslog server.
Syslog's behavior is controlled using the application configuration environment:
For example, the following config/config.exs
file sets up syslog using
level debug, facility local1, and appid myproj
use Mix.Config
config :logger, [
level: :debug,
backends: [Logger.Backends.Syslog],
syslog: [facility: :local1, appid: "myproj"]
]
You should also add the syslog
application in the mix.exs
file as shown below:
defmodule MyMod.Mixfile do
# ...
def application do
[applications: [:logger, :syslog],
mod: {MyMod, []}]
end
# ...
end
The syslog server must be configured to support remote logging. On a Redhat based
Linux distribution, you can setup remote logging by editing /etc/sysconfig/syslog
and add the -r option as shown below:
# /etc/sysconfig/syslog
...
SYSLOGD_OPTIONS="-m 0 -r"
...
If your system uses rsyslog
you should add or uncomment the following lines in your /etc/rsyslog.conf
:
$ModLoad imudp
$UDPServerRun 514
The facility also needs to be configured. Again, for Redhat distributions, edit
/etc/syslog.conf
, edit the first line below and and add the second:
#/etc/syslog.conf
...
*.info;local1.none;mail.none;authpriv.none;cron.none /var/log/messages
...
local2.* /var/log/my_elixir_project.log
Then restart the syslog
service after making the configuration changes
root@ucx20 ~]# service syslog restart
Shutting down kernel logger: [ OK ]
Shutting down system logger: [ OK ]
Starting system logger: [ OK ]
Starting kernel logger: [ OK ]
[root@ucx20 ~]#
Checkout the following test project for a working example.
syslog is copyright (c) 2014-2018 E-MetroTel.
The source code is released under the MIT License.
Check LICENSE for more information.