hauleth

hauleth

Future of Logger in Elixir

With OTP 21 and the creation of logger Elixir Logger application became quite limiting (no structured logging). I would like to discuss with how do you see the future of logging in Elixir as I have rewritten most of the logging in my application to “new” interface as this provides more flexibility. With rise of logger I also see lesser need for projects like telemetry which can be easily replaced by mentioned earlier structured logging and metadata.

What do you think?

Most Liked

martosaur

martosaur

This is my mental model of current state of the loggers:

  1. Logger handlers is the main interface for logging
  2. Logger handlers are recommended to support something called “overload protection”
  3. The default :logger_std_h handler does have an overload protection
  4. If you want to write a custom handler, you’ll have to implement overload protection, like for example, Sentry handler does.
  5. LoggerBackends is a logger handler which allows you to write logger backends which is a concept unique to this package. Custom backends won’t need overload protection as they are not logger handlers.

So my rule of thumb is as follow: logger handlers that implement overload protection can be all used as handlers alongside each other:

config :my_app, :logger, [
  {:handler, :file_log, :logger_std_h, ...},
  {:handler, :sentry, Sentry.LoggerHandler, ...}
]

Whenever you want a custom logger but don’t want to implement overload protection, you can take advantage of LoggerBackends and write a custom logger backend instead.

In reality, I’ve yet to find myself writing a custom handler as the built-in :logger_std_h in combination with filters and formatters is very very flexible. So flexible, in fact, that LoggerJSON project was completely rewritten from being a logger backend to being a formatter.

PJUllrich

PJUllrich

Author of Building Table Views with Phoenix LiveView

Aaaaah, that makes sense! I could have implemented my example (file logger) using the logger_std_h handler indeed. So, the idea here is to rather configure the existing logger_std_h or logger_disk_log_h implementations unless you need something special, but which doesn’t need overload protection. In that case, you can use the LoggerBackends library. Thanks for the clarification!

Just for future reference, I managed to implement a logger_handler myself, but it’s terrible and shouldn’t be used except for inspiration for how to use e.g. :logger_formatter, how to convert the old format-option to the new template-option, or how to convert the gregorian microsecond timestamp of the new log_event back to date and time.

It’s on GitHub here: run-elixir/assets/archived_code/file_logger.ex at main · PJUllrich/run-elixir · GitHub

And I also implemented an “old” handler, which you should now add using the LoggerBackends.add/2 function instead of the deprecated Logger.add_backend/2 function. It’s on GitHub here: run-elixir/assets/archived_code/old_file_logger.ex at main · PJUllrich/run-elixir · GitHub

chasers

chasers

Interested in what you put together if you can share? I’m currently working on Logflare and we actually need beta testers for our new logger backend.

I really like being able to keep the raw event data as you can drill into it vs the time series approach. As long as your db is fast enough to query, you’re able to insert in real-time and you’re happy with the visualization / BI tools available … I think the time series approach is less favorable.

With our Logger backend you can structure logs and add any data you want. Logflare uses BigQuery as the db and manages the BigQuery schema so you can easily query each field specifically. And BigQuery plus Data Studio is very nice although I wish it would give me minutely graphs out of the box.

hauleth

hauleth

I do not quite get what is the problem here. Erlang’s logger allows to use structured logging, so instead of (in Elixir syntax) doing Logger.info("Responded HTTP 200 in #{time}") you can do: Logger.info(%{http_response: 200, http_response_time: time}) and at the same time provide more information in metadata. This allows to eat cookie and have cookie because:

  • you can programmatically get meaningful data without processing text
  • you still can insert metadata (that aren’t part of the log message) into metadata

Grafana describes difference quite nicely, so you can see that in most (all?) cases metrics can be extracted from logs. Of course some of these logs will need to be discarded to not needlessly increase logs volume, but that can be done quite easily later.

hauleth

hauleth

I agree. I am part of the EEF Observability WG and my question isn’t whether we should rely only on the logger but whether we should include metrics in logs and then provide an logger handler that will extract these from logs and aggregate them. So everything would happen without sending high volume messages to external log handler.

So in the end there still would be some kind of aggregate that would reduce volume, so even when there happen error that is gigabyte long it shouldn’t be a problem, as most of the data would be discarded by handler anyway.

So my question is mostly about libraries like Ecto which use telemetry right now. Would it be better to keep telemetry or maybe use structured logs that could provide the same informations.

Where Next?

Popular in Discussions Top

artimath
I think I’ve tried 5 different graph database libraries in the last two days and not a single one has been able to connect to a remote/lo...
New
garrison
The Elixir ecosystem is one of our biggest strengths, and the BEAM really lends itself to native implementations (e.g. Cachex over Redis,...
New
stefannovak
Hi all, I’m going to be giving a little 20 minute tech talk at my company which uses .NET C# across all of our 100ish size IT team. I’m ...
New
f0rest8
Hi everyone :waving_hand: Posting here to showcase and announce that Metamorphic is now officially live on a public-facing domain at htt...
New
neilberkman
Carson Katri from DockYard posted today about swift-erlang-actor-system, which enables Swift programs to join Erlang clusters as distribu...
New
bartblast
Hey there! :slight_smile: I’m working on updating the Hologram website home page and would love to get your input. Current situation: ...
New
derpycoder
So, anyone got a chance to look at this?!? I’m kind of glad this came along. We can just throw this into our Auth pages and won’t have t...
New
New
Crowdhailer
It is rare to use direct calls to send in elixir. The call is normally wrapped in a function which is responsible for sending the correct...
New
ronindev
Hey everyone! :waving_hand: I just wanted to recommend https://seenode.com/ for deploying Phoenix apps. I’ve been using it recently and ...
New

Other popular topics Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
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
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
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
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
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
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
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement