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

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
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
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New

Other popular topics Top

josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
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
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
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
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
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

We're in Beta

About us Mission Statement