Skip to content

Enable lager to use the OTP logger's event pipeline#524

Open
Vagabond wants to merge 38 commits intomasterfrom
adt/lager_use_logger-option
Open

Enable lager to use the OTP logger's event pipeline#524
Vagabond wants to merge 38 commits intomasterfrom
adt/lager_use_logger-option

Conversation

@Vagabond
Copy link
Copy Markdown
Member

@Vagabond Vagabond commented Mar 1, 2020

We should really get this finished so let's try to figure out what's missing.

@Vagabond
Copy link
Copy Markdown
Member Author

Vagabond commented Mar 1, 2020

Some things we need to do:

  • Documentation
  • A way to export the current lager config as a logger config
  • An optional way to, in lager:start(), turn the lager config into a logger config programatically
  • Figure out which of the more advanced lager features can still be supported in logger
  • Figure out why log events have wrong timestamp
  • Port Lager's disk log internals to make a Logger compatible handler, because disk_log has terrible rotation

Copy link
Copy Markdown
Member

@jadeallenx jadeallenx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general. I haven't investigated the failing tests yet but I suspect they're just due to the WIP nature of these changes.

Comment thread src/lager.erl Outdated
Formatter = proplists:get_value(formatter, Config, lager_default_formatter),
FormatterConfig = proplists:get_value(formatter_config, Config, []),
%% XXX I don't think disk_log is suitable as it is, we should provide a logger compatible version of
%% lager's file_backend and try to patch disk_log upstream
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

Comment thread src/lager_sup.erl
false ->
%% set up the config, is safe even during relups
lager_config:new(),
%% TODO:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: probably should delete or update this comment

do_format(Level, Msg, Metadata, Config) ->
FormatModule = maps:get(formatter, Config, lager_default_formatter),
Timestamp = maps:get(time, Metadata),
MegaSecs = Timestamp div 1000000000000,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make these numbers macros to improve readability and maintenance sanity, please.

{application, Name} = lists:keyfind(application, 1, Report),
Formatted = error_logger_lager_h:format_reason(Reason),
{"Application ~w exited with reason: ~s", [Name, Formatted]}
end.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail on custom reports, ex.:

?LOG_INFO(#{http_reponse => 200, request_duration => Duration})

Comment thread src/lager.erl

generate_logger_config() ->
Handlers = application:get_env(lager, handlers, lager_app:default_handlers()),
{Level, NewHandlers} = generate_logger_handlers(Handlers, {notice, []}),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of "translating" Lager handlers (which will not support custom handlers anyway) to logger handlers, add new handler that will forward all messages from the logger to lager's gen_event as a compatibility layer.

Comment thread src/lager.erl
{lager_logger_formatter, #{report_cb => fun lager_logger_formatter:report_cb/1,
formatter => Formatter,
formatter_config => FormatterConfig}}}},
NewLevel = case lager_util:level_to_num(Level) > lager_util:level_to_num(CurrentLevel) of
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of that you can use logger:compare_levels/2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants