Is there any way to get all available levels of logger?

Hi, guys. Is there any way to get all available levels of logger?

I have checked the docs of Logger in Elixir or Logger in Elixir:

But didn’t find anything related to this.

I’m expecting something like:

iex> Logger.levels()
[:emergency, :alert, ...]

Is it possible to do that? If it does, can anyone give me a tip?

Thanks in advance! :smiley:

1 Like

Well you can find them by doing t :logger.level in iex but that’s not programmatic, it’s for visual inspection only.

You can start off here: https://github.com/elixir-lang/elixir/blob/a5ac8b2b2ca5093aebfa68db857e464297d2f72c/lib/iex/lib/iex/introspection.ex#L691

And then work your way down.

…Or you can just hardcode them and map them to OTP version because I am pretty sure they don’t change within patch and minor version changes:

defmodule MyApp.Config do
  @logger_levels %{
    26 => [:emergency, :alert, :critical, :error, :warning, :notice, :info, :debug]
  }
end
2 Likes

A callback: Logger.levels/0 has been merged into Elixir, and will be released in v1.16.0.

2 Likes