forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 4
/
logger.go
55 lines (46 loc) · 1.85 KB
/
logger.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
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package logging
import (
"io"
"go.uber.org/zap"
)
// Logger defines the interface that is used to keep a record of all events that
// happen to the program
type Logger interface {
io.Writer // For logging pre-formatted messages
// Log that a fatal error has occurred. The program should likely exit soon
// after this is called
Fatal(msg string, fields ...zap.Field)
// Log that an error has occurred. The program should be able to recover
// from this error
Error(msg string, fields ...zap.Field)
// Log that an event has occurred that may indicate a future error or
// vulnerability
Warn(msg string, fields ...zap.Field)
// Log an event that may be useful for a user to see to measure the progress
// of the protocol
Info(msg string, fields ...zap.Field)
// Log an event that may be useful for understanding the order of the
// execution of the protocol
Trace(msg string, fields ...zap.Field)
// Log an event that may be useful for a programmer to see when debuging the
// execution of the protocol
Debug(msg string, fields ...zap.Field)
// Log extremely detailed events that can be useful for inspecting every
// aspect of the program
Verbo(msg string, fields ...zap.Field)
// SetLevel that this logger should log to
SetLevel(level Level)
// Recovers a panic, logs the error, and rethrows the panic.
StopOnPanic()
// If a function panics, this will log that panic and then re-panic ensuring
// that the program logs the error before exiting.
RecoverAndPanic(f func())
// If a function panics, this will log that panic and then call the exit
// function, ensuring that the program logs the error, recovers, and
// executes the desired exit function
RecoverAndExit(f, exit func())
// Stop this logger and write back all meta-data.
Stop()
}