Phoenix unable to save logs in a file Production env

I am trying to save logs into a file.
In dev mode, everything is working fine
When I try these in production nothing seems to be working.
I am using the logger_file_backend package
and configured this in config.exs

config :logger,
  backends: [{LoggerFileBackend, :debug}]

config :logger, :debug,
  path: "log/debug.log",
  level: :debug

Try to find debug.log in your tree, because it might not be where You think it should.

find . -name *.log

or try to use an absolute path… and see if this works.


That should be also good:

logs_path = System.get_env("MY_APP_LOGS_PATH")
config :logger, :debug,
  path: Path.join(logs_path, "debug.log"),
  level: :debug

in config/releases.exs?


Please don’t encourage the use of releases.exs unless the Elixir version is 1.9.* or 1.10.* The file to use from Elixir 1.11.* onward is runtime.exs.


Well, release.exs still have advantages like being able to configure kernel without any additional changes in release configuration.

@VBandarupalli your logs are probably written in your working directory instead of release directory, which isn’t something you would expect. To be honest, I would suggest you to avoid logging to file directly and instead use external logging service like rsyslog or journald to manage files for you. This will also help you in future if you will decide to have centralised logging.


Good to known, but releases.exs may be deprecated in the future.

Also, releases.exs is evaluated at compile time while runtime.exs is evaluated in the machine where the application will run, thus being the correct way of configuring everything you retrieve with environment variables.

1 Like

It is already deprecated.

IIRC that is not true - both are evaluated during runtime. The main difference is that releases.exs is evaluated, it produces the sys.config, then the whole VM is restarted, while runtime.exs is (by default) evaluated within the same VM the application runs (that is the reason why you cannot configure kernel from runtime.exs by default). However I prefer to avoid both of these files and instead use “raw” sys.config or additional step before the application start for generating such file if needed. Most of the configuration is fetched from the env from within the application itself.

1 Like

You are correct, my bad. This Elixir configuration approach its just a nigntmare for me, I just got confused by it all the time.

This means that for each request the environment variable is being retrieved from the operating system environment?

No, you can do that once during application startup and then store it in place with faster access (application env or persistent_term).

1 Like