deadtrickster

deadtrickster

and those Logger patches can be removed too? can this help to collapse Logger and lager?

0
Post #12
hauleth

hauleth OP

Yes, Lager automatically attaches itself to the logger as a backend, so it will not be longer needed for any compatibility layer. What is more, such libraries will be harmful, as can cause duplicated logs or infinite logging loop.

0
Post #13
hubertlepicki

hubertlepicki

Just to check, but I think the answer is “yes”: You can use Elixir code to write these Erlang logger handlers?

0
Post #14
hauleth

hauleth OP

Elixir modules play by the same rules as Erlang modules, so yes, you can. However right now it is a little bit harder to do so as Erlang handlers are required to protect themselves against overload instead of providing system solution like Elixir does. So for now I would say that it is safer to write custom formatters rather than custom handlers.

And if that wasn’t clear, all “old” handlers still work, just if this land it would probably be softly deprecated to use them (probably not immediately, but sooner than later).

0
Post #15
hkrutzer

hkrutzer

So we can replace LoggerFileBackend with logger_disk_log_h? What does that look like?

0
Post #16
hauleth

hauleth OP

Partially yes. Configuration via kernel application isn’t directly supported (yet?), but you can run:

:logger.add_handler(:disk_log, :logger_disk_log_h, %{config: %{file: 'test.log'}})

Somewhere during the startup of the application. But remember that you can use also logger_std_h if you do not need fancy file rotation or other things as that handler also supports output to file.

1
Post #17
hkrutzer

hkrutzer

Alright, I was trying to replace my logger config with it and failing.

Will there be a way to configure logger_std_h directly from the regular logger configuration in 1.10 or will we still need a custom backend?

0
Post #18
hauleth

hauleth OP

There should be a way to do so, the discussion how to handle that is there.

1
Post #19
r-c

r-c

Referenced your post and the Logger docs for my use case.

I am trying to configure my project to use logger_std_h similar to hkrutzer. The application compiles/runs but there is no log file created. The logs only output to console. Wondering if either of you were successful in getting OTP handlers working

# config.exs
config :logger,
  backends: [:console]

config :logger, :console,
  level: :info

config :runnable, :logger,
  [
    {:handler, :default, :logger_std_h, %{level: :info, file: "test.log"}}
  ]

# runnable.exs
def start(_type, _args) do
    :logger.add_handlers(:runnable)

    Logger.info "Starting application..."

    children = [
      Greeting
    ]
    Supervisor.start_link(children, strategy: :one_for_one)
  end
0
Post #20
r-c

r-c

I realized my config for the logger was incorrect. Needed to use String.to_charlist for the file name and had to fix the map structure. Able to create the file but no log messages are written to it

0
Post #21