|
2 | 2 | %% @end |
3 | 3 | -module(grisp_connect_log). |
4 | 4 |
|
| 5 | +-behaviour(logger_formatter). |
| 6 | + |
5 | 7 | -include_lib("kernel/include/logger.hrl"). |
6 | 8 |
|
7 | 9 | % API functions |
8 | 10 | -export([get/1]). |
9 | 11 | -export([sync/1]). |
10 | 12 |
|
| 13 | +% Behaviour logger_formatter callback functions |
| 14 | +-export([check_config/1]). |
| 15 | +-export([format/2]). |
| 16 | + |
11 | 17 | %--- Macros -------------------------------------------------------------------- |
12 | 18 |
|
13 | 19 | % FixMe: |
@@ -45,6 +51,24 @@ sync(#{seq := Seq, dropped := Dropped}) -> |
45 | 51 | grisp_connect_logger_bin:sync(Seq, Dropped). |
46 | 52 |
|
47 | 53 |
|
| 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 | + |
48 | 72 | %--- Internal Functions -------------------------------------------------------- |
49 | 73 |
|
50 | 74 | jsonify(Event) -> |
|
0 commit comments