forked from StephanHCB/go-autumn-logging-zerolog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusage_test.go
52 lines (37 loc) · 2.15 KB
/
usage_test.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
41
42
43
44
45
46
47
48
49
50
51
52
package auzerolog
import (
"context"
"errors"
aulogging "github.com/StephanHCB/go-autumn-logging"
"testing"
)
func TestPlaintextLogging(t *testing.T) {
SetupPlaintextLogging()
ctx := AddLoggerToCtx(context.Background())
err := errors.New("some wonderful error")
aulogging.Logger.NoCtx().Error().Print("no context print error severity, no error object")
aulogging.Logger.Ctx(ctx).Error().WithErr(err).Print("with context print error severity, with error object")
aulogging.Logger.NoCtx().Warn().Print("no context print warn severity")
aulogging.Logger.Ctx(ctx).Warn().Print("with context print warn severity")
aulogging.Logger.NoCtx().Info().Print("no context print info severity")
aulogging.Logger.Ctx(ctx).Info().Print("with context print info severity")
aulogging.Logger.NoCtx().Debug().Print("no context print debug severity (should not show)")
aulogging.Logger.Ctx(ctx).Debug().Print("with context print debug severity (should not show)")
aulogging.Logger.NoCtx().Trace().Print("no context print trace severity (should not show)")
aulogging.Logger.Ctx(ctx).Trace().Print("with context print trace severity (should not show)")
}
func TestJsonLogging(t *testing.T) {
SetupJsonLogging("my-service")
ctx := AddLoggerToCtx(context.Background())
err := errors.New("some wonderful error")
aulogging.Logger.NoCtx().Error().Print("no context print error severity, no error object")
aulogging.Logger.Ctx(ctx).Error().WithErr(err).Print("with context print error severity, with error object")
aulogging.Logger.NoCtx().Warn().Print("no context print warn severity")
aulogging.Logger.Ctx(ctx).Warn().Print("with context print warn severity")
aulogging.Logger.NoCtx().Info().Print("no context print info severity")
aulogging.Logger.Ctx(ctx).Info().Print("with context print info severity")
aulogging.Logger.NoCtx().Debug().Print("no context print debug severity (should not show)")
aulogging.Logger.Ctx(ctx).Debug().Print("with context print debug severity (should not show)")
aulogging.Logger.NoCtx().Trace().Print("no context print trace severity (should not show)")
aulogging.Logger.Ctx(ctx).Trace().Print("with context print trace severity (should not show)")
}