github.com/MetalBlockchain/metalgo@v1.11.9/utils/logging/logger.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package logging 5 6 import ( 7 "io" 8 9 "go.uber.org/zap" 10 ) 11 12 // Func defines the method signature used for all logging methods on the Logger 13 // interface. 14 type Func func(msg string, fields ...zap.Field) 15 16 // Logger defines the interface that is used to keep a record of all events that 17 // happen to the program 18 type Logger interface { 19 io.Writer // For logging pre-formatted messages 20 21 // Log that a fatal error has occurred. The program should likely exit soon 22 // after this is called 23 Fatal(msg string, fields ...zap.Field) 24 // Log that an error has occurred. The program should be able to recover 25 // from this error 26 Error(msg string, fields ...zap.Field) 27 // Log that an event has occurred that may indicate a future error or 28 // vulnerability 29 Warn(msg string, fields ...zap.Field) 30 // Log an event that may be useful for a user to see to measure the progress 31 // of the protocol 32 Info(msg string, fields ...zap.Field) 33 // Log an event that may be useful for understanding the order of the 34 // execution of the protocol 35 Trace(msg string, fields ...zap.Field) 36 // Log an event that may be useful for a programmer to see when debuging the 37 // execution of the protocol 38 Debug(msg string, fields ...zap.Field) 39 // Log extremely detailed events that can be useful for inspecting every 40 // aspect of the program 41 Verbo(msg string, fields ...zap.Field) 42 43 // SetLevel that this logger should log to 44 SetLevel(level Level) 45 // Enabled returns true if the given level is at or above this level. 46 Enabled(lvl Level) bool 47 48 // Recovers a panic, logs the error, and rethrows the panic. 49 StopOnPanic() 50 // If a function panics, this will log that panic and then re-panic ensuring 51 // that the program logs the error before exiting. 52 RecoverAndPanic(f func()) 53 54 // If a function panics, this will log that panic and then call the exit 55 // function, ensuring that the program logs the error, recovers, and 56 // executes the desired exit function 57 RecoverAndExit(f, exit func()) 58 59 // Stop this logger and write back all meta-data. 60 Stop() 61 }