Single line logger without a custom formatter

I want to print all log messages without a new line (in case some modules use it) to not break the log parser.

I’ve noticed there is an option in erlang logger, Erlang -- logger but I don’t think I can set it up in the configuration.

Am I missing something or do I need to use a custom logger format?

Console backend by default uses the following format: "\n$time $metadata[$level] $levelpad$message\n" (read more here Logger.Backends.Console — Logger v1.12.3).
Simply remove the new line at the beginning of the pattern:

config :logger, :console, format: "$time $metadata[$level] $levelpad$message\n"
1 Like

Sorry, I wasn’t clear in my question. The $message can have a new line \n inside and is that message (or any field if possible) can only be in one line. Example:

15:56:15.487 [info] Group member (acme,coor=<0.4937.0>,cb=<0.4936.0>,generation=0):
failed to join group

I want it to be:

15:56:15.487 [info] Group member (acme,coor=<0.4937.0>,cb=<0.4936.0>,generation=0): failed to join group

There is no simple way to achieve that with current implementation of Logger. The easiest way to do so would be to provide custom formatter as {module, function} ans then remove newlines there.

3 Likes

Thanks. Already have this implemented this way, just wanted to make sure there wasn’t a simpler way.