-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_test.go
60 lines (51 loc) · 1.67 KB
/
log_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
53
54
55
56
57
58
59
60
// log_test.go
//
// Copyright (C) 2023-2024 Holger de Carne
//
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
package log_test
import (
"os"
"testing"
"time"
"github.com/hdecarne-github/go-log"
"github.com/hdecarne-github/go-log/console"
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)
func TestResetRootLogger(t *testing.T) {
_ = log.ResetRootLogger()
require.Equal(t, zerolog.InfoLevel, zerolog.GlobalLevel())
require.Equal(t, zerolog.TimeFormatUnix, zerolog.TimeFieldFormat)
}
func TestSetRootLogger(t *testing.T) {
_ = log.SetRootLogger(log.NewLogger(console.NewDefaultWriter(), true), zerolog.TraceLevel, zerolog.TimeFormatUnixMs)
require.Equal(t, zerolog.TraceLevel, zerolog.GlobalLevel())
require.Equal(t, zerolog.TimeFormatUnixMs, zerolog.TimeFieldFormat)
}
func TestSetLevel(t *testing.T) {
_ = log.ResetRootLogger()
require.Equal(t, zerolog.InfoLevel, zerolog.GlobalLevel())
log.SetLevel(zerolog.TraceLevel)
require.Equal(t, zerolog.TraceLevel, zerolog.GlobalLevel())
}
func TestSetTimeFieldFormat(t *testing.T) {
_ = log.ResetRootLogger()
require.Equal(t, time.RFC3339, zerolog.TimeFieldFormat)
log.SetTimeFieldFormat(zerolog.TimeFormatUnixMs)
require.Equal(t, zerolog.TimeFormatUnixMs, zerolog.TimeFieldFormat)
}
func TestRootLogger(t *testing.T) {
logger := log.RootLogger()
require.NotNil(t, logger)
}
func TestConfig(t *testing.T) {
configBytes, err := os.ReadFile("testdata/log.yaml")
require.NoError(t, err)
var config log.YAMLConfig
err = yaml.Unmarshal(configBytes, &config)
require.NoError(t, err)
log.SetRootLoggerFromConfig(&config)
}