pma / logger_syslog_backend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Configuration at runtime?

bortzmeyer opened this issue · comments

I'm not happy with config.exs 1) because I don't want users to edit Elixir code, but configuration files in TOML / YAML / etc 2) because I want to change the configuration after the initial startup, for instance from arguments on the command-line. So, I'm looking for a way to configure at runtime.
Application.put_env(:logger, … raises no error but changes nothing, probably because the logging system already started and does not change. Is there another way?

add_backend, remove_backend and configure_backend partially solve the problem but, for instance, I do not find how to change the syslog tag (which seems hardwired as beam.smp) or how to remove the Erlang Process ID that appears after the app_id.

@bortzmeyer Regarding the configuration I suggest looking into "mix releases" (https://hexdocs.pm/mix/1.14.4/Mix.Tasks.Release.html). You can have a config/runtime.exs that reads from environment variables.

As to seeing 'beam.smp' as the log entry tag I suspect this is being set by your log collector. The logger plugin does not itself fetch the OS process name when it writes to the Unix socket. See https://github.com/pma/logger_syslog_backend/blob/master/lib/logger_syslog_backend.ex#L119.

Can you share what is you log collector? rsyslog, syslog-ng? and what version? I don't get that result, but maybe I'm using a different collector or version.

@bortzmeyer Regarding the configuration I suggest looking into "mix releases" (https://hexdocs.pm/mix/1.14.4/Mix.Tasks.Release.html). You can have a config/runtime.exs that reads from environment variables.

As to seeing 'beam.smp' as the log entry tag I suspect this is being set by your log collector. The logger plugin does not itself fetch the OS process name when it writes to the Unix socket. See https://github.com/pma/logger_syslog_backend/blob/master/lib/logger_syslog_backend.ex#L119.

Can you share what is you log collector? rsyslog, syslog-ng? and what version? I don't get that result, but maybe I'm using a different collector or version.

The log collector is systemd.

@bortzmeyer Regarding the configuration I suggest looking into "mix releases" (https://hexdocs.pm/mix/1.14.4/Mix.Tasks.Release.html). You can have a config/runtime.exs that reads from environment variables.

As to seeing 'beam.smp' as the log entry tag I suspect this is being set by your log collector. The logger plugin does not itself fetch the OS process name when it writes to the Unix socket. See https://github.com/pma/logger_syslog_backend/blob/master/lib/logger_syslog_backend.ex#L119.

Can you share what is you log collector? rsyslog, syslog-ng? and what version? I don't get that result, but maybe I'm using a different collector or version.

runtime.exs is not a solution since it is evaluated at the very beginning, even before we parse our TOML configuration file, or the command line.

@bortzmeyer Regarding the configuration I suggest looking into "mix releases" (https://hexdocs.pm/mix/1.14.4/Mix.Tasks.Release.html). You can have a config/runtime.exs that reads from environment variables.

As to seeing 'beam.smp' as the log entry tag I suspect this is being set by your log collector. The logger plugin does not itself fetch the OS process name when it writes to the Unix socket. See https://github.com/pma/logger_syslog_backend/blob/master/lib/logger_syslog_backend.ex#L119.

Can you share what is you log collector? rsyslog, syslog-ng? and what version? I don't get that result, but maybe I'm using a different collector or version.

The logger backend https://hex.pm/packages/ex_syslogger can do it, through its configuration parameter ident. May be the trick is in its source code?

@bortzmeyer Regarding the configuration I suggest looking into "mix releases" (https://hexdocs.pm/mix/1.14.4/Mix.Tasks.Release.html). You can have a config/runtime.exs that reads from environment variables.
As to seeing 'beam.smp' as the log entry tag I suspect this is being set by your log collector. The logger plugin does not itself fetch the OS process name when it writes to the Unix socket. See https://github.com/pma/logger_syslog_backend/blob/master/lib/logger_syslog_backend.ex#L119.
Can you share what is you log collector? rsyslog, syslog-ng? and what version? I don't get that result, but maybe I'm using a different collector or version.

runtime.exs is not a solution since it is evaluated at the very beginning, even before we parse our TOML configuration file, or the command line.

Changing the backend config after starting the application can be done with Logger.configure_backend/2

Logger.configure_backend({LoggerSyslogBackend, :syslog}, app_id: :new_name)

@bortzmeyer Regarding the configuration I suggest looking into "mix releases" (https://hexdocs.pm/mix/1.14.4/Mix.Tasks.Release.html). You can have a config/runtime.exs that reads from environment variables.
As to seeing 'beam.smp' as the log entry tag I suspect this is being set by your log collector. The logger plugin does not itself fetch the OS process name when it writes to the Unix socket. See https://github.com/pma/logger_syslog_backend/blob/master/lib/logger_syslog_backend.ex#L119.
Can you share what is you log collector? rsyslog, syslog-ng? and what version? I don't get that result, but maybe I'm using a different collector or version.

The logger backend https://hex.pm/packages/ex_syslogger can do it, through its configuration parameter ident. May be the trick is in its source code?

logger_syslog_backend writes the log entry according to the format specified in RFC3164 (https://www.rfc-editor.org/rfc/rfc3164). I'm not familiar with systemd as a collector and don't know if and how it handles this format. I'm only familiar with rsyslog and syslog-ng.
I considered supporting rfc5424 (https://www.rfc-editor.org/rfc/rfc5424) as well but hasn't been a priority.

I took a quick look at ex_syslogger code and it seems to write in either a custom format or JSON.

If you can investigate how systemd handles rfc3164 and rfc5424 and determine if it handles rfc5424 better than rfc3164, I can invest some time adding support for a 2nd format set via a configuration option.

Or feel free to create a pull request to better support systemd. I'll gladly review it and push a new release to hex.pm.