Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration at runtime? #4

Open
bortzmeyer opened this issue May 2, 2023 · 7 comments
Open

Configuration at runtime? #4

bortzmeyer opened this issue May 2, 2023 · 7 comments

Comments

@bortzmeyer
Copy link

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?

@bortzmeyer
Copy link
Author

bortzmeyer commented May 2, 2023

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.

@pma
Copy link
Owner

pma commented May 2, 2023

@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
Copy link
Author

@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
Copy link
Author

@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
Copy link
Author

@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?

@pma
Copy link
Owner

pma commented May 2, 2023

@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)

@pma
Copy link
Owner

pma commented May 2, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants