Closed rlipscombe closed 6 years ago
Thanks for the feedback. I think we ought to add that in a future release too.
But it's already supported, isn't it?
https://github.com/basho/lager#custom-formatting
The placeholders pid, file, line, module, function, and node will always exist if the parse transform is used.
Apparently, it is -- there's even a unit test for it in lager_console_backend.erl
. I have no idea how I missed that.
I'm going to reopen this; it needs further investigation. In lager 3.2.1 (and possibly more recently), if I use the following config:
[date, " ", time, " ", node, " ", color, "[", severity, "]", ...
...then the node
is often displayed as Undefined
, particularly in the initial startup messages. If, instead, I use the following:
[date, " ", time, " ", {node, atom_to_list(node())}, " ", color, "[", severity, "]", ...
...then it works as expected.
Obviously, I can't use the second form in a configuration file, so I end up having to introduce a custom formatter module, as originally stated.
For example:
Erlang/OTP 19 [erts-8.3] [source] [64-bit] [smp:12:12] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V8.3 (abort with ^G)
2017-05-06 15:43:33.931 Undefined [debug] <0.86.0>@lager_handler_watcher:119 Lager installed handler error_logger_lager_h into error_logger
2017-05-06 15:43:33.941 Undefined [debug] <0.73.0> Supervisor gr_param_sup started gr_param:start_link(gr_lager_default_tracer_params) at pid <0.88.0>
2017-05-06 15:43:33.941 Undefined [debug] <0.72.0> Supervisor gr_counter_sup started gr_counter:start_link(gr_lager_default_tracer_counters) at pid <0.89.0>
2017-05-06 15:43:33.941 Undefined [debug] <0.74.0> Supervisor gr_manager_sup started gr_manager:start_link(gr_lager_default_tracer_params_mgr, gr_lager_default_tracer_params, []) at pid <0.90.0>
2017-05-06 15:43:33.941 Undefined [debug] <0.74.0> Supervisor gr_manager_sup started gr_manager:start_link(gr_lager_default_tracer_counters_mgr, gr_lager_default_tracer_counters, [{input,0},{filter,0},{output,0}]) at pid <0.91.0>
2017-05-06 15:43:34.073 Undefined [info] <0.31.0> Application lager started on node 'kitchen@roger-pc'
2017-05-06 15:43:34.430 Undefined [debug] <0.82.0>@lager_handler_watcher:119 Lager installed handler lager_backend_throttle into lager_event
(kitchen@roger-pc) 1> node().
'kitchen@roger-pc'
OK, thanks for the clarity. Hopefully someone can take a look at this soon.
Any update?
Thanks for the gentle reminder @GeraldXv
@rlipscombe - I think this should do the trick for you? Take a look.
Thank you.
@mrallen1 yes, this seems to work. Thanks.
We've had to write a custom lager formatter because we wanted the node name to appear in the log. If
lager_default_formatter
supported (e.g.)node
(analogous todate
,time
,severity
, etc.) we could use the default formatter.