-
Notifications
You must be signed in to change notification settings - Fork 0
/
logLineWrapperFormatter.go
40 lines (32 loc) · 1 KB
/
logLineWrapperFormatter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package logger
import (
"github.com/bhagyaraj1208117/andes-abc-1/core/check"
)
// logLineWrapperFormatter converts the LogLineHandler into its marshalized form
type logLineWrapperFormatter struct {
marshalizer Marshalizer
}
// NewLogLineWrapperFormatter creates a new logLineWrapperFormatter that is able to marshalize the provided logLine
func NewLogLineWrapperFormatter(marshalizer Marshalizer) (*logLineWrapperFormatter, error) {
if check.IfNil(marshalizer) {
return nil, ErrNilMarshalizer
}
return &logLineWrapperFormatter{
marshalizer: marshalizer,
}, nil
}
// Output converts the provided LogLineHandler into a slice of bytes ready for output
func (llwf *logLineWrapperFormatter) Output(line LogLineHandler) []byte {
if check.IfNil(line) {
return nil
}
buff, err := llwf.marshalizer.Marshal(line)
if err == nil {
return buff
}
return nil
}
// IsInterfaceNil returns true if there is no value under the interface
func (llwf *logLineWrapperFormatter) IsInterfaceNil() bool {
return llwf == nil
}