-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
98 lines (82 loc) · 1.64 KB
/
types.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package golog
import (
"io"
"time"
)
type Level uint8
const (
LevelPanic Level = iota + 1
LevelError
LevelWarn
LevelInfo
LevelDebug
)
func (l Level) String() string {
switch l {
case LevelPanic:
return "PANIC"
case LevelError:
return "ERROR"
case LevelInfo:
return "INFO"
case LevelWarn:
return "WARN"
case LevelDebug:
return "DEBUG"
default:
return "UNKNOWN"
}
}
type Logger interface {
Recover()
Info() Message
Warn() Message
Error() Message
Debug() Message
// Panic is a special log message type with extra decorations.
//
// By default, it doesn't exit process.
Panic() FatalMessage
// Fatal is wrapper for Logger.Panic that exits process after sending log message.
//
// Default exit code is 1.
Fatal() FatalMessage
Empty()
Module(name string) Logger
Modules() []string
SetLevel(level Level) Logger
Level() Level
SetWriter(wr io.Writer) Logger
Writer() io.Writer
AddOnLog(id string, fn LogHandler) Logger
OnLog(msg Message)
ClearHooks() Logger
ClearAll() Logger
ClearHandlers() Logger
CreateHook(name string, fn HookHandler)
Hook(name string) HookHandler
}
type HookHandler func(msg Message, arg any)
type LogHandler func(msg Message)
type Message interface {
Instance() Logger
Level() Level
Arguments() []string
UserMessage() string
Time() time.Time
Error() error
GetExitCode() int
Stack() Message
GetStack() []byte
FileWithLine() Message
SendError(err error)
Use(hook string, arg any) Message
Any(arg ...any) Message
Add(format string, args ...any) Message
Send(format string, args ...any)
fatal() FatalMessage
}
type FatalMessage interface {
Message
ExitCode(code int) Message
}