I’m using LoggerFileBackend in order to write logs to a file and trying to config the path based on the hostname. I have the following code in runtime.exs:
IO.inspect(Application.get_all_env(:logger), label: :pre_splunk_path)
config :logger, :splunk_log,
path: "/var/log/apps/my_app.#{host}.log"
IO.inspect(Application.get_all_env(:logger), label: :post_splunk_path)
For both pre_splunk_path and post_splunk_path, the path is not set:
pre_splunk_path: [
backends: [:console, {LoggerFileBackend, :splunk_log}],
...
splunk_log: [
level: :info
],
...
]
post_splunk_path: [ same ]
Afterwards when LoggerFileBackend.init is called, it isn’t set:
Calling init with name=splunk_log
config: %{
inode: nil,
io_device: nil,
level: :info,
name: :splunk_log,
path: nil,
rotate: nil
}
But if I check from the console after startup, it is set:
1> Application.get_all_env(:logger)
[
backends: [:console, {LoggerFileBackend, :splunk_log}],
...
splunk_log: [
level: :info,
path: "/var/log/apps/myapp.console-1631022785-3082.log"
],
...
]
And at this point I can force reconfigure from the console and it works:
2> :gen_event.call(Logger, {LoggerFileBackend, :splunk_log},
{:configure, path: "/var/log/apps/myapp.console-1631025756-20171.log"})
So any idea how I can have the runtime config take affect properly?