Documentation ¶
Index ¶
- Constants
- func Debug(a ...interface{})
- func Debugf(f string, a ...interface{})
- func Error(a ...interface{})
- func Errorf(f string, a ...interface{})
- func Fatal(a ...interface{})
- func Fatalf(f string, a ...interface{})
- func Info(a ...interface{})
- func Infof(f string, a ...interface{})
- func IsTerminal(w io.Writer) bool
- func Print(a ...interface{})
- func Printf(f string, a ...interface{})
- func Println(a ...interface{})
- func SetCallerOffset(offset int)
- func SetDefaultLevel(l Level)
- func SetDefaultLogger(logger Logger)
- func SetOutputLevel(l Level)
- func Warn(a ...interface{})
- func Warnf(f string, a ...interface{})
- type CallerOffsetter
- type DebugLogger
- type ErrorLogger
- type FatalLogger
- type InfoLogger
- type Level
- type LeveledLogger
- func (l *LeveledLogger) Debug(a ...interface{})
- func (l *LeveledLogger) DebugDepth(depth int, a ...interface{})
- func (l *LeveledLogger) Debugf(format string, a ...interface{})
- func (l *LeveledLogger) DebugfDepth(depth int, format string, a ...interface{})
- func (l *LeveledLogger) DefaultLevel() Level
- func (l *LeveledLogger) Error(a ...interface{})
- func (l *LeveledLogger) ErrorDepth(depth int, a ...interface{})
- func (l *LeveledLogger) Errorf(format string, a ...interface{})
- func (l *LeveledLogger) ErrorfDepth(depth int, format string, a ...interface{})
- func (l *LeveledLogger) Fatal(a ...interface{})
- func (l *LeveledLogger) FatalDepth(depth int, a ...interface{})
- func (l *LeveledLogger) Fatalf(format string, a ...interface{})
- func (l *LeveledLogger) FatalfDepth(depth int, format string, a ...interface{})
- func (l *LeveledLogger) Info(a ...interface{})
- func (l *LeveledLogger) InfoDepth(depth int, a ...interface{})
- func (l *LeveledLogger) Infof(format string, a ...interface{})
- func (l *LeveledLogger) InfofDepth(depth int, format string, a ...interface{})
- func (l *LeveledLogger) OutputLevel() Level
- func (l *LeveledLogger) Print(a ...interface{})
- func (l *LeveledLogger) PrintDepth(depth int, a ...interface{})
- func (l *LeveledLogger) Printf(format string, a ...interface{})
- func (l *LeveledLogger) PrintfDepth(depth int, format string, a ...interface{})
- func (l *LeveledLogger) Println(a ...interface{})
- func (l *LeveledLogger) PrintlnDepth(depth int, a ...interface{})
- func (l *LeveledLogger) SetCallerOffset(offset int)
- func (l *LeveledLogger) SetDefaultLevel(level Level)
- func (l *LeveledLogger) SetOutputLevel(level Level)
- func (l *LeveledLogger) Warn(a ...interface{})
- func (l *LeveledLogger) WarnDepth(depth int, a ...interface{})
- func (l *LeveledLogger) Warnf(format string, a ...interface{})
- func (l *LeveledLogger) WarnfDepth(depth int, format string, a ...interface{})
- type Leveler
- type Logger
- type PrintLogger
- type WarnLogger
Examples ¶
Constants ¶
const ( ColorBlue = "\x1b[0;34m" ColorGreen = "\x1b[0;32m" ColorYellow = "\x1b[0;33m" ColorRed = "\x1b[0;31m" ColorMegenta = "\x1b[0;35m" ColorRST = "\x1b[0;m" )
Colors.
const ( Ldate = 1 << iota // the date in the local time zone: 2009/01/23 Ltime // the time in the local time zone: 01:23:23 Lmicroseconds // microsecond resolution: 01:23:23.123123. assumes Ltime. Llongfile // full file name and line number: /a/b/c/d.go:23 Lshortfile // final file name element and line number: d.go:23. overrides Llongfile LUTC // if Ldate or Ltime is set, use UTC rather than the local time zone LstdFlags = Ldate | Ltime // initial values for the standard logger )
Flags from standard package log are copied here to avoid importing two packages with the same name log.
These flags define which text to prefix to each log entry generated by the Logger.
Variables ¶
This section is empty.
Functions ¶
func Debugf ¶
func Debugf(f string, a ...interface{})
Debugf calls the same method on the default logger.
func Errorf ¶
func Errorf(f string, a ...interface{})
Errorf calls the same method on the default logger.
func Fatalf ¶
func Fatalf(f string, a ...interface{})
Fatalf calls the same method on the default logger.
func Infof ¶
func Infof(f string, a ...interface{})
Infof calls the same method on the default logger.
func IsTerminal ¶
IsTerminal returns true if the given writer supports colored output.
func Printf ¶
func Printf(f string, a ...interface{})
Printf calls the same method on the default logger.
func SetCallerOffset ¶
func SetCallerOffset(offset int)
SetCallerOffset calls the same method on the default logger.
func SetDefaultLevel ¶
func SetDefaultLevel(l Level)
SetDefaultLevel calls the same method on the default logger.
func SetDefaultLogger ¶
func SetDefaultLogger(logger Logger)
SetDefaultLogger sets the default logger with CallerOffset set. NOTE: this function is supposed to be called while DefaultLogger is not in use, it's not goroutine safe for performance.
func SetOutputLevel ¶
func SetOutputLevel(l Level)
SetOutputLevel calls the same method on the default logger.
Types ¶
type CallerOffsetter ¶
type CallerOffsetter interface {
SetCallerOffset(int)
}
CallerOffsetter provides the ability of setting caller offset.
type DebugLogger ¶
type DebugLogger interface { Debug(...interface{}) Debugf(string, ...interface{}) DebugDepth(int, ...interface{}) DebugfDepth(int, string, ...interface{}) }
DebugLogger represents a logger with Debug* APIs.
type ErrorLogger ¶
type ErrorLogger interface { Error(...interface{}) Errorf(string, ...interface{}) ErrorDepth(int, ...interface{}) ErrorfDepth(int, string, ...interface{}) }
ErrorLogger represents a logger with Error* APIs.
type FatalLogger ¶
type FatalLogger interface { Fatal(...interface{}) Fatalf(string, ...interface{}) FatalDepth(int, ...interface{}) FatalfDepth(int, string, ...interface{}) }
FatalLogger represents a logger with Fatal* APIs.
type InfoLogger ¶
type InfoLogger interface { Info(...interface{}) Infof(string, ...interface{}) InfoDepth(int, ...interface{}) InfofDepth(int, string, ...interface{}) }
InfoLogger represents a logger with Info* APIs.
type Level ¶
type Level int32
Level represents level of logging.
Log levels from low to high. NOTE: FATAL is the highest, NOTSET is the lowest.
func DefaultLevel ¶
func DefaultLevel() Level
DefaultLevel calls the same method on the default logger.
func LevelFromString ¶
LevelFromString parses string to Level. NOTSET is returned if the given string can not be recognized.
func OutputLevel ¶
func OutputLevel() Level
OutputLevel calls the same method on the default logger.
type LeveledLogger ¶
type LeveledLogger struct {
// contains filtered or unexported fields
}
LeveledLogger has the ability of logging with different levels.
func NewLeveledLogger ¶
func NewLeveledLogger(out io.Writer, flag int) *LeveledLogger
NewLeveledLogger creates a LeveledLogger with given output writer and flag. The flag argument defines the logging properties, it is the same as log.New. You could use flags from THIS log package to avoid importing standard package log.
func NewLeveledLoggerWithColor ¶
func NewLeveledLoggerWithColor(out io.Writer, flag int, colored bool) *LeveledLogger
NewLeveledLoggerWithColor is NewLeveledLogger with an additional colored parameter indicating if color is forced.
func (*LeveledLogger) Debug ¶
func (l *LeveledLogger) Debug(a ...interface{})
Debug prints log with level DEBUG. Arguments are handled in the manner of fmt.Print.
func (*LeveledLogger) DebugDepth ¶
func (l *LeveledLogger) DebugDepth(depth int, a ...interface{})
DebugDepth acts as Debug but uses depth to determine which call frame to log DebugDepth(0, "msg") is the same as Debug("msg")
func (*LeveledLogger) Debugf ¶
func (l *LeveledLogger) Debugf(format string, a ...interface{})
Debugf prints log with level DEBUG. Arguments are handled in the manner of fmt.Printf.
func (*LeveledLogger) DebugfDepth ¶
func (l *LeveledLogger) DebugfDepth(depth int, format string, a ...interface{})
DebugfDepth acts as Debugf but uses depth to determine which call frame to log DebugfDepth(0, "msg") is the same as Debugf("msg")
func (*LeveledLogger) DefaultLevel ¶
func (l *LeveledLogger) DefaultLevel() Level
DefaultLevel is the level used by Print* methods.
func (*LeveledLogger) Error ¶
func (l *LeveledLogger) Error(a ...interface{})
Error prints log with level ERROR. Arguments are handled in the manner of fmt.Print.
func (*LeveledLogger) ErrorDepth ¶
func (l *LeveledLogger) ErrorDepth(depth int, a ...interface{})
ErrorDepth acts as Error but uses depth to determine which call frame to log ErrorDepth(0, "msg") is the same as Error("msg")
func (*LeveledLogger) Errorf ¶
func (l *LeveledLogger) Errorf(format string, a ...interface{})
Errorf prints log with level ERROR. Arguments are handled in the manner of fmt.Printf.
func (*LeveledLogger) ErrorfDepth ¶
func (l *LeveledLogger) ErrorfDepth(depth int, format string, a ...interface{})
ErrorfDepth acts as Errorf but uses depth to determine which call frame to log ErrorfDepth(0, "msg") is the same as Errorf("msg")
func (*LeveledLogger) Fatal ¶
func (l *LeveledLogger) Fatal(a ...interface{})
Fatal prints log with level FATA then os.Exit(1). Arguments are handled in the manner of fmt.Print.
func (*LeveledLogger) FatalDepth ¶
func (l *LeveledLogger) FatalDepth(depth int, a ...interface{})
FatalDepth acts as Fatal but uses depth to determine which call frame to log FatalDepth(0, "msg") is the same as Fatal("msg")
func (*LeveledLogger) Fatalf ¶
func (l *LeveledLogger) Fatalf(format string, a ...interface{})
Fatalf prints log with level FATA then os.Exit(1). Arguments are handled in the manner of fmt.Printf.
func (*LeveledLogger) FatalfDepth ¶
func (l *LeveledLogger) FatalfDepth(depth int, format string, a ...interface{})
FatalfDepth acts as Fatalf but uses depth to determine which call frame to log FatalfDepth(0, "msg") is the same as Fatalf("msg")
func (*LeveledLogger) Info ¶
func (l *LeveledLogger) Info(a ...interface{})
Info prints log with level INFO. Arguments are handled in the manner of fmt.Print.
func (*LeveledLogger) InfoDepth ¶
func (l *LeveledLogger) InfoDepth(depth int, a ...interface{})
InfoDepth acts as Info but uses depth to determine which call frame to log InfoDepth(0, "msg") is the same as Info("msg")
func (*LeveledLogger) Infof ¶
func (l *LeveledLogger) Infof(format string, a ...interface{})
Infof prints log with level INFO. Arguments are handled in the manner of fmt.Printf.
func (*LeveledLogger) InfofDepth ¶
func (l *LeveledLogger) InfofDepth(depth int, format string, a ...interface{})
InfofDepth acts as Infof but uses depth to determine which call frame to log InfofDepth(0, "msg") is the same as Infof("msg")
func (*LeveledLogger) OutputLevel ¶
func (l *LeveledLogger) OutputLevel() Level
OutputLevel returns the minimal Level of log that will be outputted. Levels lower than this will be ignored.
func (*LeveledLogger) Print ¶
func (l *LeveledLogger) Print(a ...interface{})
Print prints log with DefaultLevel. Arguments are handled in the manner of fmt.Print.
func (*LeveledLogger) PrintDepth ¶
func (l *LeveledLogger) PrintDepth(depth int, a ...interface{})
PrintDepth acts as Print but uses depth to determine which call frame to log PrintDepth(0, "msg") is the same as Print("msg")
func (*LeveledLogger) Printf ¶
func (l *LeveledLogger) Printf(format string, a ...interface{})
Printf prints log with DefaultLevel. Arguments are handled in the manner of fmt.Printf.
func (*LeveledLogger) PrintfDepth ¶
func (l *LeveledLogger) PrintfDepth(depth int, format string, a ...interface{})
PrintfDepth acts as Printf but uses depth to determine which call frame to log PrintfDepth(0, "msg") is the same as Printf("msg")
func (*LeveledLogger) Println ¶
func (l *LeveledLogger) Println(a ...interface{})
Println prints log with DefaultLevel. Arguments are handled in the manner of fmt.Println.
func (*LeveledLogger) PrintlnDepth ¶
func (l *LeveledLogger) PrintlnDepth(depth int, a ...interface{})
PrintlnDepth acts as Printfln but uses depth to determine which call frame to log PrintflnDepth(0, "msg") is the same as Printfln("msg")
func (*LeveledLogger) SetCallerOffset ¶
func (l *LeveledLogger) SetCallerOffset(offset int)
SetCallerOffset sets the offset used in runtime.Caller(3 + offset) while getting file name and line number. NOTE: Do not call this while logging, it's not goroutine safe.
func (*LeveledLogger) SetDefaultLevel ¶
func (l *LeveledLogger) SetDefaultLevel(level Level)
SetDefaultLevel sets the DefaultLevel atomically.
func (*LeveledLogger) SetOutputLevel ¶
func (l *LeveledLogger) SetOutputLevel(level Level)
SetOutputLevel sets the OutputLevel atomically.
func (*LeveledLogger) Warn ¶
func (l *LeveledLogger) Warn(a ...interface{})
Warn prints log with level WARN. Arguments are handled in the manner of fmt.Print.
func (*LeveledLogger) WarnDepth ¶
func (l *LeveledLogger) WarnDepth(depth int, a ...interface{})
WarnDepth acts as Warn but uses depth to determine which call frame to log WarnDepth(0, "msg") is the same as Warn("msg")
func (*LeveledLogger) Warnf ¶
func (l *LeveledLogger) Warnf(format string, a ...interface{})
Warnf prints log with level WARN. Arguments are handled in the manner of fmt.Printf.
func (*LeveledLogger) WarnfDepth ¶
func (l *LeveledLogger) WarnfDepth(depth int, format string, a ...interface{})
WarnfDepth acts as Warnf but uses depth to determine which call frame to log WarnfDepth(0, "msg") is the same as Warnf("msg")
type Leveler ¶
type Leveler interface { DefaultLevel() Level SetDefaultLevel(Level) OutputLevel() Level SetOutputLevel(Level) }
Leveler contains level-related APIs.
type Logger ¶
type Logger interface { DebugLogger PrintLogger InfoLogger WarnLogger ErrorLogger FatalLogger Leveler CallerOffsetter }
Logger represents a full-featured logger.
Example ¶
l := NewLoggerWithColor(os.Stdout, 0, false) // Color and time-related flags should be disabled in testing. // While you may want to use the following instead: // l := NewLeveledLogger(os.Stdout, LstdFlags) l.SetOutputLevel(INFO) l.Debug("Output level is INFO.") l.Info("Thus debug is not printed.") l.SetOutputLevel(DEBUG) l.Debug("The above line enables debug.")
Output: I Thus debug is not printed. D The above line enables debug.
func DefaultLogger ¶
func DefaultLogger() Logger
DefaultLogger returns the default logger which writes to os.Stdout.