Maxximiliann

Maxximiliann

Auto rotating logs by file size

Installed:

logger_file_backend 0.0.10

logrotate for Ubuntu (config file)

Trying to get logs to automatically rotate when they hit 125MB with logrotate to no avail. How can logs be automatically rotated straight from Elixir?

Marked As Solved

derek-zhou

derek-zhou

What I meant is:

config :myapp, :logger,
  [
    {:handler, :my_disk_log, :logger_disk_log_h,
         %{config: %{file: 'test.log',
                     max_no_bytes: 100_000_000},
           level: :info}
    }
  ]

Untested, but you get the idea. It is a 2 level map, and each have it own set of keys. The outer level is the general configuration for any log_handler, the inner one is the configuration specifically for :logger_disk_log_h

Also Liked

derek-zhou

derek-zhou

Apparently logger_std_h gains circular rotation in OTP-15479 which is released in 2019-03-12 (roughly 2 years ago). And it was marked internal at that time.

In any case, it is dead simple to migrate to logger_std_h if anyone want to. all configurations are basically the same.

derek-zhou

derek-zhou

I was referring to this sentence in the changelog. Probably “internal” does not mean non-public:

The standard logger handler, logger_std_h, now has a new internal feature for log rotation.

As for filename rotation, I prefer the scheme of svlogd from runit, which is somewhere between the two:

  • lastest file name is fixed
  • old files are not renamed

On one hand I want the latest file easily identifiable. On the other hand, I prefer old files just stay what they are. If something went wrong and the log files are rotating fast it is very frustrating to pin down the one file that has the log entries you want to analysis.

hauleth

hauleth

It meant how it is implemented, not about “publicity” of an API.

It seems like more reasonable approach, indeed. However changing it now would be a breaking change. However I hope that logger_olp and logger_sup will became public API in near future, which mean that there will be a way to implement such feature directly in Erlang. However personally I still prefer to use syslog or journal for logging, and do not bother with rotation within the application itself. In that way, there is no problem with rotation or “where will logs land” as you have centralised place to manage everything.

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
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
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48342 226
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
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
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 52673 488
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New

We're in Beta

About us Mission Statement