-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.go
52 lines (43 loc) · 1.1 KB
/
logging.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
// SPDX-License-Identifier: Apache-2.0
package logging
import (
"io"
"testing"
"github.com/loopholelabs/logging/loggers/noop"
"github.com/loopholelabs/logging/loggers/slog"
"github.com/loopholelabs/logging/loggers/zerolog"
"github.com/loopholelabs/logging/types"
testingAdapter "github.com/loopholelabs/logging/adapters/testing"
)
type Kind int
const (
Noop Kind = iota
Zerolog
Slog
)
// New creates a new logger based on the given kind, source, and output
// and a default level of Info.
func New(kind Kind, source string, output io.Writer) types.RootLogger {
switch kind {
case Noop:
return noop.New(types.InfoLevel)
case Zerolog:
return zerolog.New(source, types.InfoLevel, output)
case Slog:
return slog.New(source, types.InfoLevel, output)
default:
return nil
}
}
func Test(t testing.TB, kind Kind, source string) types.RootLogger {
switch kind {
case Noop:
return noop.New(types.InfoLevel)
case Zerolog:
return zerolog.New(source, types.InfoLevel, testingAdapter.New(t))
case Slog:
return slog.New(source, types.InfoLevel, testingAdapter.New(t))
default:
return nil
}
}