Total Lines | 36 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | package zla |
||
2 | |||
3 | import ( |
||
4 | "github.com/rs/zerolog" |
||
5 | |||
6 | e2hformat "github.com/cdleo/go-e2h/formatter" |
||
7 | ) |
||
8 | |||
9 | type ContextHook struct { |
||
10 | ref string |
||
11 | } |
||
12 | |||
13 | func (h ContextHook) Run(e *zerolog.Event, level zerolog.Level, msg string) { |
||
14 | 1 | e.Str("ref", h.ref) |
|
15 | } |
||
16 | |||
17 | type LevelMsgHook struct { |
||
18 | level string |
||
19 | where string |
||
20 | message string |
||
21 | } |
||
22 | |||
23 | func (h LevelMsgHook) Run(e *zerolog.Event, level zerolog.Level, msg string) { |
||
24 | 1 | e.Str("level", h.level) |
|
25 | 1 | e.Str("message", h.message) |
|
26 | 1 | e.Str("where", h.where) |
|
27 | } |
||
28 | |||
29 | type ErrorHook struct { |
||
30 | err error |
||
31 | params e2hformat.Params |
||
32 | formatter e2hformat.Formatter |
||
33 | } |
||
34 | |||
35 | func (h ErrorHook) Run(e *zerolog.Event, level zerolog.Level, msg string) { |
||
36 | 1 | e.RawJSON("details", []byte(h.formatter.Format(h.err, h.params))) |
|
37 | } |
||
38 |