Documentation ¶
Index ¶
- Variables
- func Sanitize(s string) string
- func SanitizeArgs(a []interface{}) []interface{}
- type Color
- type Config
- type Factory
- type Highlight
- type Level
- type Log
- func (l *Log) AssertDeferredNoError(f func() error)
- func (l *Log) AssertDeferredTrue(f func() bool, format string, args ...interface{})
- func (l *Log) AssertNoError(err error)
- func (l *Log) AssertTrue(b bool, format string, args ...interface{})
- func (l *Log) Debug(format string, args ...interface{})
- func (l *Log) Error(format string, args ...interface{})
- func (l *Log) Fatal(format string, args ...interface{})
- func (l *Log) Info(format string, args ...interface{})
- func (l *Log) RecoverAndExit(f, exit func())
- func (l *Log) RecoverAndPanic(f func())
- func (l *Log) SetContextualDisplayingEnabled(enabled bool)
- func (l *Log) SetDisplayLevel(lvl Level)
- func (l *Log) SetDisplayingEnabled(enabled bool)
- func (l *Log) SetLogLevel(lvl Level)
- func (l *Log) SetLoggingEnabled(enabled bool)
- func (l *Log) SetPrefix(prefix string)
- func (l *Log) Stop()
- func (l *Log) StopOnPanic()
- func (l *Log) Verbo(format string, args ...interface{})
- func (l *Log) Warn(format string, args ...interface{})
- func (l *Log) Write(p []byte) (int, error)
- type Logger
- type NoFactory
- type NoIOWriter
- type NoLog
- func (NoLog) AssertDeferredNoError(f func() error)
- func (NoLog) AssertDeferredTrue(f func() bool, format string, args ...interface{})
- func (NoLog) AssertNoError(error)
- func (NoLog) AssertTrue(b bool, format string, args ...interface{})
- func (NoLog) Debug(format string, args ...interface{})
- func (NoLog) Error(format string, args ...interface{})
- func (NoLog) Fatal(format string, args ...interface{})
- func (NoLog) Info(format string, args ...interface{})
- func (NoLog) RecoverAndExit(f, exit func())
- func (NoLog) RecoverAndPanic(f func())
- func (NoLog) SetContextualDisplayingEnabled(bool)
- func (NoLog) SetDisplayLevel(Level)
- func (NoLog) SetDisplayingEnabled(bool)
- func (NoLog) SetLogLevel(Level)
- func (NoLog) SetLoggingEnabled(bool)
- func (NoLog) SetPrefix(string)
- func (NoLog) Stop()
- func (NoLog) StopOnPanic()
- func (NoLog) Verbo(format string, args ...interface{})
- func (NoLog) Warn(format string, args ...interface{})
- func (NoLog) Write([]byte) (int, error)
- type RotatingWriter
- type RoutineID
- type Stacktrace
Constants ¶
This section is empty.
Variables ¶
var DefaultLogDirectory = fmt.Sprintf("~/.%s/logs", constants.AppName)
DefaultLogDirectory is the default directory where logs are saved
Functions ¶
func SanitizeArgs ¶ added in v1.3.0
func SanitizeArgs(a []interface{}) []interface{}
Types ¶
type Color ¶
type Color string
const ( Black Color = "\033[0;30m" DarkGray Color = "\033[1;30m" Red Color = "\033[0;31m" LightRed Color = "\033[1;31m" Green Color = "\033[0;32m" LightGreen Color = "\033[1;32m" Orange Color = "\033[0;33m" Yellow Color = "\033[1;33m" Blue Color = "\033[0;34m" LightBlue Color = "\033[1;34m" Purple Color = "\033[0;35m" LightPurple Color = "\033[1;35m" Cyan Color = "\033[0;36m" LightCyan Color = "\033[1;36m" LightGray Color = "\033[0;37m" White Color = "\033[1;37m" Reset Color = "\033[0;0m" Bold Color = "\033[;1m" Reverse Color = "\033[;7m" )
Colors
type Config ¶
type Config struct { RotationInterval time.Duration FileSize, RotationSize, FlushSize int DisableLogging, DisableDisplaying, DisableContextualDisplaying, DisableFlushOnWrite, Assertions bool LogLevel, DisplayLevel Level DisplayHighlight Highlight Directory, MsgPrefix, LoggerName string }
Config defines the configuration of a logger
func DefaultConfig ¶
DefaultConfig returns a logger configuration with default parameters
type Factory ¶
type Factory interface { // Make creates a new logger with name [name] Make(name string) (Logger, error) // MakeChain creates a new logger to log the events of chain [chainID] MakeChain(chainID string) (Logger, error) // MakeChainChild creates a new sublogger for a [name] module of a chain [chainId] MakeChainChild(chainID string, name string) (Logger, error) // Close stops and clears all of a Factory's instantiated loggers Close() }
Factory creates new instances of different types of Logger
func NewFactory ¶
NewFactory returns a new instance of a Factory producing loggers configured with the values set in the [config] parameter
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log implements the Logger interface
func (*Log) AssertDeferredNoError ¶
AssertDeferredNoError implements the Logger interface
func (*Log) AssertDeferredTrue ¶
AssertDeferredTrue implements the Logger interface
func (*Log) AssertNoError ¶
AssertNoError implements the Logger interface
func (*Log) AssertTrue ¶
AssertTrue implements the Logger interface
func (*Log) RecoverAndExit ¶ added in v0.8.0
func (l *Log) RecoverAndExit(f, exit func())
RecoverAndExit implements the Logger interface
func (*Log) RecoverAndPanic ¶
func (l *Log) RecoverAndPanic(f func())
RecoverAndPanic implements the Logger interface
func (*Log) SetContextualDisplayingEnabled ¶
SetContextualDisplayingEnabled implements the Logger interface
func (*Log) SetDisplayLevel ¶
SetDisplayLevel implements the Logger interface
func (*Log) SetDisplayingEnabled ¶
SetDisplayingEnabled implements the Logger interface
func (*Log) SetLoggingEnabled ¶
SetLoggingEnabled implements the Logger interface
type Logger ¶
type Logger interface { io.Writer // For logging pre-formated messages // Log that a fatal error has occurred. The program should likely exit soon // after this is called Fatal(format string, args ...interface{}) // Log that an error has occurred. The program should be able to recover // from this error Error(format string, args ...interface{}) // Log that an event has occurred that may indicate a future error or // vulnerability Warn(format string, args ...interface{}) // Log an event that may be useful for a user to see to measure the progress // of the protocol Info(format string, args ...interface{}) // Log an event that may be useful for a programmer to see when debuging the // execution of the protocol Debug(format string, args ...interface{}) // Log extremely detailed events that can be useful for inspecting every // aspect of the program Verbo(format string, args ...interface{}) // If assertions are enabled, will result in a panic if err is non-nil AssertNoError(err error) // If assertions are enabled, will result in a panic if b is false AssertTrue(b bool, format string, args ...interface{}) // If assertions are enabled, the function will be called and will result in // a panic the returned value is non-nil AssertDeferredNoError(f func() error) // If assertions are enabled, the function will be called and will result in // a panic the returned value is false AssertDeferredTrue(f func() bool, format string, args ...interface{}) // 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()) // Only events above or equal to the level set will be logged SetLogLevel(Level) // Only logged events above or equal to the level set will be logged SetDisplayLevel(Level) // Add a prefix to all logged messages SetPrefix(string) // Enable or disable logging SetLoggingEnabled(bool) // Enable or disable the display of logged events SetDisplayingEnabled(bool) // Enable or disable the display of contextual information for logged events SetContextualDisplayingEnabled(bool) // Stop this logger and write back all meta-data. Stop() }
Logger defines the interface that is used to keep a record of all events that happen to the program
type NoIOWriter ¶ added in v0.8.0
type NoIOWriter struct{}
NoIOWriter is a mock Writer that does not write to any underlying source
func (*NoIOWriter) Initialize ¶ added in v0.8.0
func (nw *NoIOWriter) Initialize(Config) (int, error)
Initialize ...
func (*NoIOWriter) Write ¶ added in v0.8.0
func (nw *NoIOWriter) Write(p []byte) (int, error)
Write ...
func (*NoIOWriter) WriteString ¶ added in v0.8.0
func (nw *NoIOWriter) WriteString(s string) (int, error)
WriteString ...
type NoLog ¶
type NoLog struct{}
NoLog ...
func (NoLog) AssertDeferredNoError ¶
AssertDeferredNoError ...
func (NoLog) AssertDeferredTrue ¶
AssertDeferredTrue ...
func (NoLog) AssertTrue ¶
AssertTrue ...
func (NoLog) RecoverAndExit ¶ added in v0.8.0
func (NoLog) RecoverAndExit(f, exit func())
RecoverAndExit ...
func (NoLog) SetContextualDisplayingEnabled ¶
SetContextualDisplayingEnabled ...
func (NoLog) SetDisplayingEnabled ¶
SetDisplayingEnabled ...
type RotatingWriter ¶ added in v0.8.0
type RotatingWriter interface { // Creates the log file if it doesn't exist or resume writing to it if it does Initialize(Config) (int, error) // Flushes the writer Flush() error // Writes [b] to the log file Write(b []byte) (int, error) // Writes [s] to the log file WriteString(s string) (int, error) // Closes the log file Close() error // Rotates the log files. Always keeps the current log in the same file. // Rotated log files are stored as by appending an integer to the log file name, // from 1 to the RotationSize defined in the configuration. 1 being the most // recently rotated log file. Rotate() error }
RotatingWriter allows for rotating a stream writer
type Stacktrace ¶
type Stacktrace struct {
Global bool
}
Stacktrace can print the current stacktrace
func (Stacktrace) String ¶
func (st Stacktrace) String() string