Enable lager to use the OTP logger's event pipeline#524
Enable lager to use the OTP logger's event pipeline#524
Conversation
|
Some things we need to do:
|
jadeallenx
left a comment
There was a problem hiding this comment.
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.
| 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 |
| false -> | ||
| %% set up the config, is safe even during relups | ||
| lager_config:new(), | ||
| %% TODO: |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
This will fail on custom reports, ex.:
?LOG_INFO(#{http_reponse => 200, request_duration => Duration})|
|
||
| generate_logger_config() -> | ||
| Handlers = application:get_env(lager, handlers, lager_app:default_handlers()), | ||
| {Level, NewHandlers} = generate_logger_handlers(Handlers, {notice, []}), |
There was a problem hiding this comment.
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.
| {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 |
There was a problem hiding this comment.
Instead of that you can use logger:compare_levels/2.
We should really get this finished so let's try to figure out what's missing.