marcin

marcin

Configure log directory for Phoenix app

Hello!
I’m deploying my Phoenix app using mix_systemd package, to run it as systemd unit file. The app’s runtime is in /srv/appname/current,

Problem: The app tries to create log files under /srv/appname/current/log/error.log and /srv/appname/current/console.log. I would like to configure it to create the log files under /var/log/appname.

I have no idea where this file creation comes from. My configuration does not contain logging to files:

 Application.get_env :logger, :backends
[:console, Sentry.LoggerBackend]

Despite this, I’m getting these errors and the process crashes:

Jul 22 17:18:50 steinem proca[102362]: 17:18:50.230 [error] Failed to open log file log/error.log with error permission denied
Jul 22 17:18:50 steinem proca[102362]: 17:18:50.231 [error] Failed to open log file log/console.log with error permission denied

I do not know which elixir module emits these errors (no traceback). Is this some “standard” behaviour for releases? How can I control it?

Marked As Solved

marcin

marcin

… oh actually I can!
I spot lager library:

deps/lager/src/lager_file_backend.erl
131:                    ?INT_LOG(error, "Failed to open log file ~ts with error ~s", [Name, file:format_error(Reason)]),
692:                "Failed to open log file " ++ TestLog ++ " with error permission denied",
739:                "Failed to open log file " ++ TestLog ++ " with error permission denied",

lets investigate…

So lager is an erlang logger library pulled in by rabbitmq client package.

It needs to be configured in one of compiled config files, so config.exs or prod.exs for instance:

config :lager,
  log_root: '/var/log/appname'

Also Liked

LostKobrakai

LostKobrakai

Starting a release as daemon will make it write logs to disk by default (as nobody is watching stdout). Your path doesn’t match that default though.

LostKobrakai

LostKobrakai

I’d also look if you actually need lager. It’s been replaced in recent versions by erlangs :logger and the integration of it into elixir.

hauleth

hauleth

In the case of @marcin it is dependency of dependency (RabbitMQ). Hopefully in future lager will also be backed by logger so there will be only one place to configure logging (but we still will need to find a way to configure logger in development, but that is discussion for some other time).

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

We're in Beta

About us Mission Statement