ExSyslogger is custom backend for Elixir Logger
that logs to syslog by wrapping erlang-syslog.
This project is a fork of exsyslog.
jason
dependency is set to optional and you should explicitly add it to your dependency list)Add :ex_syslogger
as a dependency in your mix.exs
file
defp deps do
[
{:ex_syslogger, "~> 1.5"}
]
end
defp deps do
[
{:ex_syslogger, "~> 1.3"}
]
end
Add :ex_syslogger
to your list of included_applications
:
def application do
[included_applications: [:ex_syslogger]]
end
If you going to use JsonFormatter please we sure that jason
is added as dependency in your application. For older Elixir versions it might be needed to add it to the list of applications as above.
ExSyslogger is a Logger custom backend, as such, it relies on Logger application.
On your config.exs
file tell Logger
that it should add ExSyslogger
backend
config :logger,
backends: [
{ExSyslogger, :ex_syslogger_error},
{ExSyslogger, :ex_syslogger_debug},
{ExSyslogger, :ex_syslogger_json}
]
With the configuration above, Logger
application will add three ExSyslogger
backend with the name {ExSyslogger, :ex_syslogger_error}
, {ExSyslogger, :ex_syslogger_debug}
and {ExSyslogger, :ex_syslogger_json}
.
You might notice that instead of just passing the Module name, we're passing a tuple with {Module name, backend configuration name}
. This allow us to have multiple backends with different configuration. Let's configure the backends:
config :logger, :ex_syslogger_error,
level: :error,
format: "$date $time [$level] $levelpad$node $metadata $message",
metadata: [:module, :line, :function],
ident: "MyApplication",
facility: :local0,
option: [:pid, :cons]
config :logger, :ex_syslogger_debug,
level: :debug,
format: "$date $time [$level] $message",
ident: "MyApplication",
facility: :local1,
option: [:pid, :perror]
config :logger, :ex_syslogger_json,
level: :debug,
format: "$message",
formatter: ExSyslogger.JsonFormatter,
metadata: [:module, :line, :function],
ident: "MyApplication",
facility: :local1,
option: :pid
:info
:console
backend (Logger.Formatter). It defaults to "\n$date $time [$level] $levelpad$node $metadata $message\n"
:console
backend Logger.Formatter. It defaults to []
"Elixir"
:local0
. More documentation on erlang-syslog:ndelay
. More documentation on erlang-syslogExSyslogger by default uses Logger.Formatter. However, it comes with a JSON formatter that formats a given log entry to a JSON string. NOTE: ExSyslogger.JsonFormatter
can be use as an example if one wants to build his own formatter.
To build a custom formatter the formatter needs to implement the following functions:
compile(str)
Compiles a format string
compile(binary | nil) :: [Logger.Formatter.pattern | binary]
compile({atom, atom}) :: {atom, atom}
format(format, level, msg, timestamp, metadata, config_metadata)
Takes a compiled format and transforms it on a string that will be pass to syslog
format({atom, atom} | [Logger.Formatter.pattern | binary], Logger.level, Logger.message, Logger.Formatter.time, Keyword.t, [atom]) :: IO.chardata
To add the custom formatter you will need to set the formatter
property on the configuration as exemplified above with ExSyslogger.JsonFormatter
In another shell:
$ tail -f /var/log/syslog
(Mac users)
$ tail -f /var/log/system.log
NOTE Mac has a funny syslog. Your info logs might not show up. You'll need to configure your Mac syslog.
Clone the project, go to examples/examples1 and run the project ($ iex -S mix
).
Erlang/OTP 18 [erts-7.0.2] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Interactive Elixir (1.0.5) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Example1.run
2015-09-11 15:26:18.850 [error] nonode@nohost module=Elixir.Example1 function=run/0 line=5 Hello ExSyslogger
:ok
You should see on the tail -f
something similar to:
exsyslog_error
backend
Sep 11 16:26:18 bt.local MyApplication[12833]: 2015-09-11 15:26:18.850 [error] nonode@nohost module=Elixir.Example1 function=run/0 line=5 Hello ExSyslogger
exsyslog_debug
backend
Sep 11 16:26:18 bt.local MyApplication[12833]: 2015-09-11 15:26:18.850 [error] Hello ExSyslogger
exsyslog_json
backend
Sep 11 16:26:18 bt.local MyApplication[12833]: {"node":"nonode@nohost","module":"Elixir.Example1","message":"Hello ExSyslogger","line":5,"level":"error","function":"run/0"}
The source code is released under the MIT License. Check LICENSE for more information.
Mishka Installer is a system plugin manager and run time installer for elixir
Jalali DateField support for Django model
MishkaCms an open source and real time API base CMS Powered by Elixir and Phoenix
A Jalaali (Jalali, Persian, Khorshidi, Shamsi) calendar system implemention for Elixir
Simple tool for parse and create structured JSON for Nginx error logs
In this project, we implemented a topic detection system on Twitter. This system reads tweets from a data stream and assigns them to one of the existing clusters or a new one. Each cluster acts as an agent, which makes the proposed approach a multi-agent...
ExGuard is a mix command to handle events on file system modifications
A curated list of awesome Slim framework packages and resources.