Documentation ¶
Overview ¶
Package log supplies more advanced features than go orign log package.
It supports log different level: trace, debug, info, warn, error, fatal.
It also supports different log handlers which you can log to stdout, file, socket, etc...
Use
import "github.com/Paraplouis/replicator/log" //log with different level log.Info("hello world") log.Error("hello world") //create a logger with specified handler h := NewStreamHandler(os.Stdout) l := log.NewDefault(h) l.Info("hello world")
Index ¶
- Constants
- func Debug(args ...interface{})
- func DebugJson(body interface{})
- func Debugf(format string, args ...interface{})
- func Debugln(args ...interface{})
- func Error(args ...interface{})
- func ErrorJson(body interface{})
- func Errorf(format string, args ...interface{})
- func Errorln(args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Fatalln(args ...interface{})
- func Info(args ...interface{})
- func InfoJson(body interface{})
- func Infof(format string, args ...interface{})
- func Infoln(args ...interface{})
- func Panic(args ...interface{})
- func Panicf(format string, args ...interface{})
- func Panicln(args ...interface{})
- func Print(args ...interface{})
- func PrintJson(body interface{})
- func Printf(format string, args ...interface{})
- func Println(args ...interface{})
- func SetDefaultLogger(l *Logger)
- func SetLevel(level Level)
- func SetLevelByName(name string)
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- func Warnln(args ...interface{})
- type FileHandler
- type Handler
- type Level
- type Logger
- func (l *Logger) Close()
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Debugln(args ...interface{})
- func (l *Logger) Error(args ...interface{})
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Errorln(args ...interface{})
- func (l *Logger) Fatal(args ...interface{})
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) Fatalln(args ...interface{})
- func (l *Logger) Info(args ...interface{})
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) Infoln(args ...interface{})
- func (l *Logger) Output(callDepth int, level Level, msg string)
- func (l *Logger) OutputJson(callDepth int, level Level, body interface{})
- func (l *Logger) Panic(args ...interface{})
- func (l *Logger) Panicf(format string, args ...interface{})
- func (l *Logger) Panicln(args ...interface{})
- func (l *Logger) Print(args ...interface{})
- func (l *Logger) Printf(format string, args ...interface{})
- func (l *Logger) Println(args ...interface{})
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) SetLevelByName(name string)
- func (l *Logger) Warn(args ...interface{})
- func (l *Logger) Warnf(format string, args ...interface{})
- func (l *Logger) Warnln(args ...interface{})
- type NullHandler
- type RotatingFileHandler
- type StreamHandler
- type TimeRotatingFileHandler
Constants ¶
const ( WhenSecond = iota WhenMinute WhenHour WhenDay )
TimeRotating way
const ( Ltime = 1 << iota // time format "2006/01/02 15:04:05" Lfile // file.go:123 Llevel // [Trace|Debug|Info...] )
Logger flag
Variables ¶
This section is empty.
Functions ¶
func Debugf ¶
func Debugf(format string, args ...interface{})
Debugf records the log with debug level
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf records the log with error level
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf records the log with fatal level and exits
func Panicf ¶
func Panicf(format string, args ...interface{})
Panicf records the log with fatal level and panics
func Panicln ¶
func Panicln(args ...interface{})
Panicln records the log with fatal level and panics
func Printf ¶
func Printf(format string, args ...interface{})
Printf records the log with trace level
func SetLevelByName ¶
func SetLevelByName(name string)
SetLevelByName changes the logger level by name
Types ¶
type FileHandler ¶
type FileHandler struct {
// contains filtered or unexported fields
}
FileHandler writes log to a file.
func NewFileHandler ¶
func NewFileHandler(fileName string, flag int) (*FileHandler, error)
NewFileHandler creates a FileHander
type Logger ¶
type Logger struct { // TODO: support logger.Contextual loggers.Advanced // contains filtered or unexported fields }
Logger is the logger to record log
func NewDefault ¶
NewDefault creates default logger with specified handler and flag: Ltime|Lfile|Llevel
func (*Logger) Debug ¶
func (l *Logger) Debug(args ...interface{})
Debug records the log with debug level
func (*Logger) Debugln ¶
func (l *Logger) Debugln(args ...interface{})
Debugln records the log with debug level
func (*Logger) Error ¶
func (l *Logger) Error(args ...interface{})
Error records the log with error level
func (*Logger) Errorln ¶
func (l *Logger) Errorln(args ...interface{})
Errorln records the log with error level
func (*Logger) Fatal ¶
func (l *Logger) Fatal(args ...interface{})
Fatal records the log with fatal level and exits
func (*Logger) Fatalln ¶
func (l *Logger) Fatalln(args ...interface{})
Fatalln records the log with fatal level and exits
func (*Logger) Info ¶
func (l *Logger) Info(args ...interface{})
Info records the log with info level
func (*Logger) Infoln ¶
func (l *Logger) Infoln(args ...interface{})
Infoln records the log with info level
func (*Logger) OutputJson ¶
Output json format records the log with special callstack depth and log level.
func (*Logger) Panic ¶
func (l *Logger) Panic(args ...interface{})
Panic records the log with fatal level and panics
func (*Logger) Panicln ¶
func (l *Logger) Panicln(args ...interface{})
Panicln records the log with fatal level and panics
func (*Logger) Print ¶
func (l *Logger) Print(args ...interface{})
Print records the log with trace level
func (*Logger) Println ¶
func (l *Logger) Println(args ...interface{})
Println records the log with trace level
func (*Logger) SetLevelByName ¶
SetLevelByName sets log level by name
func (*Logger) Warn ¶
func (l *Logger) Warn(args ...interface{})
Warn records the log with warn level
type NullHandler ¶
type NullHandler struct { }
NullHandler does nothing, it discards anything.
func NewNullHandler ¶
func NewNullHandler() (*NullHandler, error)
NewNullHandler creates a NullHandler
type RotatingFileHandler ¶
type RotatingFileHandler struct {
// contains filtered or unexported fields
}
RotatingFileHandler writes log a file, if file size exceeds maxBytes, it will backup current file and open a new one.
max backup file number is set by backupCount, it will delete oldest if backups too many.
func NewRotatingFileHandler ¶
func NewRotatingFileHandler(fileName string, maxBytes int, backupCount int) (*RotatingFileHandler, error)
NewRotatingFileHandler creates a RotatingFileHandler
func (*RotatingFileHandler) Close ¶
func (h *RotatingFileHandler) Close() error
Close implements Handler interface
type StreamHandler ¶
type StreamHandler struct {
// contains filtered or unexported fields
}
StreamHandler writes logs to a specified io Writer, maybe stdout, stderr, etc...
func NewStreamHandler ¶
func NewStreamHandler(w io.Writer) (*StreamHandler, error)
NewStreamHandler creates a StreamHandler
func (*StreamHandler) Close ¶
func (h *StreamHandler) Close() error
Close implements Handler interface
type TimeRotatingFileHandler ¶
type TimeRotatingFileHandler struct {
// contains filtered or unexported fields
}
TimeRotatingFileHandler writes log to a file, it will backup current and open a new one, with a period time you sepecified.
refer: http://docs.python.org/2/library/logging.handlers.html. same like python TimedRotatingFileHandler.
func NewTimeRotatingFileHandler ¶
func NewTimeRotatingFileHandler(baseName string, when int8, interval int) (*TimeRotatingFileHandler, error)
NewTimeRotatingFileHandler creates a TimeRotatingFileHandler
func (*TimeRotatingFileHandler) Close ¶
func (h *TimeRotatingFileHandler) Close() error
Close implements Handler interface