dogger
/
exported.go
102 строки · 1.7 Кб
1package dogger2
3import (4"context"5"github.com/nikwo/dogger/format"6"io"7"os"8
9"github.com/nikwo/dogger/level"10)
11
12func WithContext(ctx context.Context) Logger {13l := createChildLogger(ctx, level.TRACE)14return l15}
16
17func WithFields(entry string, value interface{}) Logger {18l := createChildLogger(context.Background(), level.TRACE)19l.fields = make(map[string]interface{})20l.fields[entry] = value21return l22}
23
24func Trace(input interface{}) {25l := createChildLogger(context.Background(), level.TRACE)26if !l.acceptedLevel(level.TRACE) {27return28}29
30l.formOutput(input)31l.flush()32}
33
34func Debug(input interface{}) {35l := createChildLogger(context.Background(), level.DEBUG)36if !l.acceptedLevel(level.DEBUG) {37return38}39
40l.formOutput(input)41l.flush()42}
43
44func Info(input interface{}) {45l := createChildLogger(context.Background(), level.INFO)46if !l.acceptedLevel(level.INFO) {47return48}49
50l.formOutput(input)51l.flush()52}
53
54func Warn(input interface{}) {55l := createChildLogger(context.Background(), level.WARN)56if !l.acceptedLevel(level.WARN) {57return58}59
60l.formOutput(input)61l.flush()62}
63
64func Error(input interface{}) {65l := createChildLogger(context.Background(), level.ERROR)66if !l.acceptedLevel(level.ERROR) {67return68}69
70l.formOutput(input)71l.flush()72}
73
74func SetLevel(level level.Level) {75lockIO()76defer unlockIO()77log.lvl = level78}
79
80func SetWriter(customWriter io.Writer) {81lockIO()82defer unlockIO()83writer = customWriter84}
85
86func SetFormatter(formatter format.Format) {87lockIO()88defer unlockIO()89log.formatter = formatter90}
91
92func ExportDefaultLogger() Logger {93return log94}
95
96func init() {97log = &logger{98lvl: level.TRACE,99formatter: format.DefaultFormatter(),100}101writer = os.Stdout102}
103