Documentation ¶
Overview ¶
Package log provide the standard interface of logging for what any go libraries want strip off the direct dependency from a known logging library.
Index ¶
- Constants
- Variables
- func CalcStackFrames(skipFramesAtFirst int) (skipped int)
- func Debug(args ...interface{})
- func Debugf(msg string, args ...interface{})
- func Error(args ...interface{})
- func Errorf(msg string, args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(msg string, args ...interface{})
- func GetDebugMode() bool
- func GetOutput() (w io.Writer)
- func GetTraceMode() bool
- func InDebugging() bool
- func InDevelopingTime() (status bool)
- func InDockerEnvSimple() (status bool)
- func InTesting() bool
- func InTestingT(args []string) bool
- func InTracing() bool
- func Info(args ...interface{})
- func Infof(msg string, args ...interface{})
- func IsDebuggerAttached() bool
- func Panic(args ...interface{})
- func Panicf(msg string, args ...interface{})
- func Print(args ...interface{})
- func Printf(msg string, args ...interface{})
- func Println(args ...interface{})
- func SetDebugLevel(hits int)
- func SetDebugMode(b bool)
- func SetLevel(l Level)
- func SetLogger(l Logger)
- func SetOutput(w io.Writer)
- func SetTraceLevel(hits int)
- func SetTraceMode(b bool)
- func Setup()
- func Trace(args ...interface{})
- func Tracef(msg string, args ...interface{})
- func VDebug(args ...interface{})
- func VDebugf(msg string, args ...interface{})
- func VError(args ...interface{})
- func VErrorf(msg string, args ...interface{})
- func VFatal(args ...interface{})
- func VFatalf(msg string, args ...interface{})
- func VInfo(args ...interface{})
- func VInfof(msg string, args ...interface{})
- func VPanic(args ...interface{})
- func VPanicf(msg string, args ...interface{})
- func VPrint(args ...interface{})
- func VPrintf(msg string, args ...interface{})
- func VPrintln(args ...interface{})
- func VTrace(args ...interface{})
- func VTracef(msg string, args ...interface{})
- func VWarn(args ...interface{})
- func VWarnf(msg string, args ...interface{})
- func Warn(args ...interface{})
- func Warnf(msg string, args ...interface{})
- type Any
- type BuilderFunc
- type L
- type LF
- type Level
- type Logger
- type LoggerConfig
- type LoggerExt
- type Opt
- type SL
- type SystemdLogger
Constants ¶
const VerboseEnabled = false
VerboseEnabled identify whether `--tags=verbose` has been defined in go building
Variables ¶
var AllLevels = []Level{ PanicLevel, FatalLevel, ErrorLevel, WarnLevel, InfoLevel, DebugLevel, TraceLevel, OffLevel, }
AllLevels is a constant exposing all logging levels
var VeryQuietEnabled = false
VeryQuietEnabled identify whether `--tags=veryquiet` has been defined in go building
Functions ¶
func CalcStackFrames ¶ added in v1.5.19
CalcStackFrames _
func Debug ¶ added in v0.2.3
func Debug(args ...interface{})
Debug prints all args to stdin if logging level is greater than DebugLevel It would be optimized to discard if `--tags=veryquiet` was been defined.
func Debugf ¶ added in v0.1.16
func Debugf(msg string, args ...interface{})
Debugf prints the text to stdin if logging level is greater than DebugLevel It would be optimized to discard if `--tags=veryquiet` was been defined.
func Error ¶ added in v0.2.3
func Error(args ...interface{})
Error prints all args to stderr It would be optimized to discard if `--tags=veryquiet` was been defined.
func Errorf ¶ added in v0.1.16
func Errorf(msg string, args ...interface{})
Errorf prints the text to stderr It would be optimized to discard if `--tags=veryquiet` was been defined.
func Fatal ¶ added in v0.2.3
func Fatal(args ...interface{})
Fatal is equivalent to Printf() followed by a call to os.Exit(1). It would be optimized to discard if `--tags=veryquiet` was been defined.
If all args are nil, Fatal will return to caller normally.
func Fatalf ¶ added in v0.1.16
func Fatalf(msg string, args ...interface{})
Fatalf is equivalent to Printf() followed by a call to os.Exit(1). It would be optimized to discard if `--tags=veryquiet` was been defined.
func GetDebugMode ¶ added in v0.1.13
func GetDebugMode() bool
GetDebugMode return the debug boolean flag generally.
GetDebugMode() = InDebugging() || internalStates.debugMode InDebugging() = isdelve.Enabled
func GetTraceMode ¶ added in v0.1.13
func GetTraceMode() bool
GetTraceMode return the trace boolean flag generally.
GetTraceMode() = InTracing() || internalStates.traceMode InTracing() = trace.IsEnabled()
func InDebugging ¶ added in v0.1.13
func InDebugging() bool
InDebugging return the status if cmdr was built with debug mode / or the app running under a debugger attached.
To enable the debugger attached mode for cmdr, run `go build` with `-tags=delve` options. eg:
go run -tags=delve ./cli go build -tags=delve -o my-app ./cli
For Goland, you can enable this under 'Run/Debug Configurations', by adding the following into 'Go tool arguments:'
-tags=delve
InDebugging() is a synonym to IsDebuggerAttached().
NOTE that `isdelve` algor is from https://stackoverflow.com/questions/47879070/how-can-i-see-if-the-goland-debugger-is-running-in-the-program
noinspection GoBoolExpressions
func InDevelopingTime ¶ added in v1.6.17
func InDevelopingTime() (status bool)
InDevelopingTime detects whether is in developing time.
If the main program has been built as an executable binary, we would assume which is not in developing time.
If log.GetDebugMode() is true, that's in developing time too.
func InDockerEnvSimple ¶ added in v1.6.17
func InDockerEnvSimple() (status bool)
InDockerEnvSimple detects whether is running within docker container environment.
InDockerEnvSimple finds if `/.dockerenv` exists or not.
func InTesting ¶ added in v0.2.3
func InTesting() bool
InTesting detects whether is running under go test mode
func InTestingT ¶ added in v0.2.3
InTestingT detects whether is running under 'go test' mode
func Info ¶ added in v0.2.3
func Info(args ...interface{})
Info prints all args to stdin if logging level is greater than InfoLevel It would be optimized to discard if `--tags=veryquiet` was been defined.
func Infof ¶ added in v0.1.16
func Infof(msg string, args ...interface{})
Infof prints the text to stdin if logging level is greater than InfoLevel It would be optimized to discard if `--tags=veryquiet` was been defined.
func IsDebuggerAttached ¶ added in v1.6.17
func IsDebuggerAttached() bool
IsDebuggerAttached return the status if cmdr was built with debug mode / or the app running under a debugger attached.
To enable the debugger attached mode for cmdr, run `go build` with `-tags=delve` options. eg:
go run -tags=delve ./cli go build -tags=delve -o my-app ./cli
For Goland, you can enable this under 'Run/Debug Configurations', by adding the following into 'Go tool arguments:'
-tags=delve
IsDebuggerAttached() is a synonym to InDebugging().
NOTE that `isdelve` algor is from https://stackoverflow.com/questions/47879070/how-can-i-see-if-the-goland-debugger-is-running-in-the-program
noinspection GoBoolExpressions
func Panic ¶ added in v0.2.3
func Panic(args ...interface{})
Panic is equivalent to Printf() followed by a call to panic(). It would be optimized to discard if `--tags=veryquiet` was been defined.
If all args are nil, Panic will return to caller normally.
func Panicf ¶ added in v0.1.16
func Panicf(msg string, args ...interface{})
Panicf is equivalent to Printf() followed by a call to panic(). It would be optimized to discard if `--tags=veryquiet` was been defined.
func Print ¶ added in v0.2.3
func Print(args ...interface{})
Print calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Print. It would be optimized to discard if `--tags=veryquiet` was been defined.
func Printf ¶ added in v0.1.16
func Printf(msg string, args ...interface{})
Printf calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Printf. It would be optimized to discard if `--tags=veryquiet` was been defined.
func Println ¶ added in v0.2.3
func Println(args ...interface{})
Println calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Println. It would be optimized to discard if `--tags=veryquiet` was been defined.
func SetDebugLevel ¶ added in v1.6.18
func SetDebugLevel(hits int)
func SetDebugMode ¶ added in v0.1.13
func SetDebugMode(b bool)
SetDebugMode set the debug boolean flag generally
func SetLogger ¶ added in v0.1.17
func SetLogger(l Logger)
SetLogger transfer an instance into log package-level value
func SetTraceLevel ¶ added in v1.6.18
func SetTraceLevel(hits int)
func SetTraceMode ¶ added in v0.1.13
func SetTraceMode(b bool)
SetTraceMode set the trace boolean flag generally
func Trace ¶ added in v0.2.3
func Trace(args ...interface{})
Trace prints all args to stdin if logging level is greater than TraceLevel It would be optimized to discard if `--tags=veryquiet` was been defined.
func Tracef ¶ added in v0.1.16
func Tracef(msg string, args ...interface{})
Tracef prints the text to stdin if logging level is greater than TraceLevel It would be optimized to discard if `--tags=veryquiet` was been defined.
func VDebug ¶ added in v1.5.39
func VDebug(args ...interface{})
VDebug prints all args to stdin if logging level is greater than DebugLevel It would be optimized to discard except `--tags=verbose` was been defined.
func VDebugf ¶ added in v1.5.39
func VDebugf(msg string, args ...interface{})
VDebugf prints the text to stdin if logging level is greater than DebugLevel It would be optimized to discard except `--tags=verbose` was been defined.
func VError ¶ added in v1.5.39
func VError(args ...interface{})
VError prints all args to stderr It would be optimized to discard except `--tags=verbose` was been defined.
func VErrorf ¶ added in v1.5.39
func VErrorf(msg string, args ...interface{})
VErrorf prints the text to stderr It would be optimized to discard except `--tags=verbose` was been defined.
func VFatal ¶ added in v1.5.39
func VFatal(args ...interface{})
VFatal is equivalent to Printf() followed by a call to os.Exit(1). It would be optimized to discard except `--tags=verbose` was been defined.
func VFatalf ¶ added in v1.5.39
func VFatalf(msg string, args ...interface{})
VFatalf is equivalent to Printf() followed by a call to os.Exit(1). It would be optimized to discard except `--tags=verbose` was been defined.
func VInfo ¶ added in v1.5.39
func VInfo(args ...interface{})
VInfo prints all args to stdin if logging level is greater than InfoLevel It would be optimized to discard except `--tags=verbose` was been defined.
func VInfof ¶ added in v1.5.39
func VInfof(msg string, args ...interface{})
VInfof prints the text to stdin if logging level is greater than InfoLevel It would be optimized to discard except `--tags=verbose` was been defined.
func VPanic ¶ added in v1.5.39
func VPanic(args ...interface{})
VPanic is equivalent to Printf() followed by a call to panic(). It would be optimized to discard except `--tags=verbose` was been defined.
func VPanicf ¶ added in v1.5.39
func VPanicf(msg string, args ...interface{})
VPanicf is equivalent to Printf() followed by a call to panic(). It would be optimized to discard except `--tags=verbose` was been defined.
func VPrint ¶ added in v1.5.39
func VPrint(args ...interface{})
VPrint calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Print. It would be optimized to discard except `--tags=verbose` was been defined.
func VPrintf ¶ added in v1.5.39
func VPrintf(msg string, args ...interface{})
VPrintf calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Printf. It would be optimized to discard except `--tags=verbose` was been defined.
func VPrintln ¶ added in v1.5.39
func VPrintln(args ...interface{})
VPrintln calls Output to print to the standard logger. Arguments are handled in the manner of fmt.Println. It would be optimized to discard except `--tags=verbose` was been defined.
func VTrace ¶ added in v1.5.39
func VTrace(args ...interface{})
VTrace prints all args to stdin if logging level is greater than TraceLevel It would be optimized to discard except `--tags=verbose` was been defined.
func VTracef ¶ added in v1.5.39
func VTracef(msg string, args ...interface{})
VTracef prints the text to stdin if logging level is greater than TraceLevel. It would be optimized to discard except `--tags=verbose` was been defined.
func VWarn ¶ added in v1.5.39
func VWarn(args ...interface{})
VWarn prints all args to stderr It would be optimized to discard except `--tags=verbose` was been defined.
func VWarnf ¶ added in v1.5.39
func VWarnf(msg string, args ...interface{})
VWarnf prints the text to stderr It would be optimized to discard except `--tags=verbose` was been defined.
Types ¶
type BuilderFunc ¶ added in v0.3.11
type BuilderFunc func(config *LoggerConfig) (logger Logger)
BuilderFunc provides a function prototype for creating a hedzr/log & hedzr/logex -compliant creator.
type L ¶ added in v0.2.3
type L interface { // Trace prints all args to stdin if logging level is greater than TraceLevel Trace(args ...interface{}) // Debug prints all args to stdin if logging level is greater than DebugLevel Debug(args ...interface{}) // Info prints all args to stdin if logging level is greater than InfoLevel Info(args ...interface{}) // Warn prints all args to stderr Warn(args ...interface{}) // Error prints all args to stderr Error(args ...interface{}) // Fatal is equivalent to Printf() followed by a call to os.Exit(1). Fatal(args ...interface{}) // Panic is equivalent to Printf() followed by a call to panic(). Panic(args ...interface{}) // Print calls Output to print to the standard logger. // Arguments are handled in the manner of fmt.Print. Print(args ...interface{}) // Println calls Output to print to the standard logger. // Arguments are handled in the manner of fmt.Println. Println(args ...interface{}) }
L provides a basic logger interface
type LF ¶ added in v0.2.3
type LF interface { SL // Tracef prints the text to stdin if logging level is greater than TraceLevel Tracef(msg string, args ...interface{}) // Debugf prints the text to stdin if logging level is greater than DebugLevel Debugf(msg string, args ...interface{}) // Infof prints the text to stdin if logging level is greater than InfoLevel Infof(msg string, args ...interface{}) // Warnf prints the text to stderr Warnf(msg string, args ...interface{}) // Errorf prints the text to stderr Errorf(msg string, args ...interface{}) // Fatalf is equivalent to Printf() followed by a call to os.Exit(1). Fatalf(msg string, args ...interface{}) // Panicf is equivalent to Printf() followed by a call to panic(). Panicf(msg string, args ...interface{}) // Printf calls Output to print to the standard logger. // Arguments are handled in the manner of fmt.Printf. Printf(msg string, args ...interface{}) }
LF provides a L logger interface and format prototypes (such as Debugf...)
type Level ¶
type Level uint32
Level type
const ( // PanicLevel level, highest level of severity. Logs and then calls panic with the // message passed to Debug, Info, ... PanicLevel Level = iota // FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the // logging level is set to Panic. FatalLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. ErrorLevel // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel // InfoLevel level. General operational entries about what's going on inside the // application. InfoLevel // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel // TraceLevel level. Designates finer-grained informational events than the Debug. TraceLevel // OffLevel level. The logger will be shutdown. OffLevel )
These are the different logging levels. You can set the logging level to log on your instance of logger, obtained with `logrus.New()`.
func ParseLevel ¶
ParseLevel takes a string level and returns the Logrus log level constant.
func (Level) MarshalText ¶
MarshalText convert Level to string and []byte
func (*Level) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Logger ¶
type Logger interface { LF // SetLevel sets the logging level SetLevel(lvl Level) // GetLevel returns the current logging level GetLevel() Level // SetOutput setup the logging output device SetOutput(out io.Writer) // GetOutput returns the current logging output device GetOutput() (out io.Writer) // Setup will be invoked once an instance created Setup() // AddSkip adds an extra count to skip stack frames AddSkip(skip int) Logger }
Logger is a minimal logger with no more dependencies
func AsLogger ¶ added in v0.2.3
AsLogger converts a logger to LF or Logger type (with Infof(...), ... prototypes)
func FromSystemdLogger ¶ added in v0.3.18
func FromSystemdLogger(sl SystemdLogger) Logger
FromSystemdLogger converts a SystemdLogger to Logger so that you can put it into `log` system via log.SetLogger.
func GetLogger ¶ added in v0.1.17
func GetLogger() Logger
GetLogger returns the package-level logger globally
func NewDummyLogger ¶ added in v0.1.5
func NewDummyLogger() Logger
NewDummyLogger return a dummy logger
func NewDummyLoggerWithConfig ¶ added in v0.3.11
func NewDummyLoggerWithConfig(config *LoggerConfig) Logger
NewDummyLoggerWithConfig return a dummy logger
type LoggerConfig ¶
type LoggerConfig struct { Enabled bool Backend string // zap, sugar, logrus Level string // level Format string // text, json, ... Target string // console, file, console+file Directory string // logdir, for file AllToErrorDevice bool // DebugMode bool `json:"-" yaml:"-"` TraceMode bool `json:"-" yaml:"-"` // MaxSize is the maximum size in megabytes of the log file before it gets // rotated. It defaults to 100 megabytes. MaxSize int `json:"maxsize" yaml:"maxsize"` // MaxAge is the maximum number of days to retain old log files based on the // timestamp encoded in their filename. Note that a day is defined as 24 // hours and may not exactly correspond to calendar days due to daylight // savings, leap seconds, etc. The default is not to remove old log files // based on age. MaxAge int `json:"maxage" yaml:"maxage"` // MaxBackups is the maximum number of old log files to retain. The default // is to retain all old log files (though MaxAge may still cause them to get // deleted.) MaxBackups int `json:"maxbackups" yaml:"maxbackups"` // LocalTime determines if the time used for formatting the timestamps in // backup files is the computer's local time. The default is to use UTC // time. LocalTime bool `json:"localtime" yaml:"localtime"` // Compress determines if the rotated log files should be compressed // using gzip. The default is not to perform compression. Compress bool `json:"compress" yaml:"compress"` ExtraSkip int ShortTimestamp bool // remove year field for a shorter timestamp stringify TimestampFormat string // never used }
LoggerConfig is used for creating a minimal logger with no more dependencies
func NewLoggerConfig ¶
func NewLoggerConfig(opts ...Opt) *LoggerConfig
NewLoggerConfig returns a default LoggerConfig
func NewLoggerConfigWith ¶ added in v0.1.17
func NewLoggerConfigWith(enabled bool, backend, level string, opts ...Opt) *LoggerConfig
NewLoggerConfigWith returns a default LoggerConfig
type Opt ¶ added in v1.5.0
type Opt func(lc *LoggerConfig)
Opt _
func WithTimestamp ¶ added in v1.5.0
WithTimestamp _
type SL ¶ added in v1.5.31
type SL interface { With(key string, val interface{}) Logger WithFields(fields map[string]interface{}) Logger }
SL provides a structural logging interface
type SystemdLogger ¶ added in v0.3.18
type SystemdLogger interface { Error(v ...interface{}) error Warning(v ...interface{}) error Info(v ...interface{}) error Errorf(format string, a ...interface{}) error Warningf(format string, a ...interface{}) error Infof(format string, a ...interface{}) error }
SystemdLogger writes to the system log.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package color provides a wrapped standard output device like printf but with colored enhancements.
|
Package color provides a wrapped standard output device like printf but with colored enhancements. |
Package detects collects all detector, buildtags, environment settings in one place.
|
Package detects collects all detector, buildtags, environment settings in one place. |
Package dir provides a series of directory/file operations
|
Package dir provides a series of directory/file operations |