Skip to content

Commit 133c915

Browse files
authored
Add log formatter with option to only log report description (#62)
1 parent e72d8bb commit 133c915

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,27 @@ You can copy paste these settings:
195195
].
196196
```
197197

198+
To simplify the log on the device while still sending full log reports to
199+
griso.io, use grisp_connect_log log formatter with single-line in the default
200+
log handler:
201+
202+
```
203+
{handler, default, logger_std_h, #{
204+
level => notice,
205+
formatter => {grisp_connect_log, #{
206+
legacy_header => false,
207+
single_line => true,
208+
description_only => true
209+
}},
210+
filter_default => log,
211+
filters => [
212+
% Filter out supervisor progress reports so TLS certificates
213+
% are not swamping the console if the level is set to info...
214+
{disable_progress, {fun logger_filters:progress/2, stop}}
215+
]
216+
}}
217+
```
218+
198219
## Development
199220

200221
### Local Development

src/grisp_connect_log.erl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
%% @end
33
-module(grisp_connect_log).
44

5+
-behaviour(logger_formatter).
6+
57
-include_lib("kernel/include/logger.hrl").
68

79
% API functions
810
-export([get/1]).
911
-export([sync/1]).
1012

13+
% Behaviour logger_formatter callback functions
14+
-export([check_config/1]).
15+
-export([format/2]).
16+
1117
%--- Macros --------------------------------------------------------------------
1218

1319
% FixMe:
@@ -45,6 +51,24 @@ sync(#{seq := Seq, dropped := Dropped}) ->
4551
grisp_connect_logger_bin:sync(Seq, Dropped).
4652

4753

54+
%--- Beahviour logger_formatter Callback Functions -----------------------------
55+
56+
check_config(Config = #{description_only := Bool})
57+
when is_boolean(Bool) ->
58+
logger_formatter:check_config(maps:remove(description_only, Config));
59+
check_config(#{description_only := V}) ->
60+
{error, {invalid_formatter_config, ?MODULE, {description_only, V}}};
61+
check_config(Config) ->
62+
logger_formatter:check_config(Config).
63+
64+
format(LogEvent = #{msg := {report, #{description := Desc}}},
65+
Config = #{description_only := true}) when is_binary(Desc) ->
66+
logger_formatter:format(LogEvent#{msg := {string, Desc}},
67+
maps:remove(description_only, Config));
68+
format(LogEvent, Config) ->
69+
logger_formatter:format(LogEvent, maps:remove(description_only, Config)).
70+
71+
4872
%--- Internal Functions --------------------------------------------------------
4973

5074
jsonify(Event) ->

0 commit comments

Comments
 (0)