Documentation ¶
Overview ¶
log package 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
//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
- Variables
- func Buss(format string, v ...interface{})
- func Close()
- func DLOG(fileName string, format string, v ...interface{})
- func Debug(format string, v ...interface{})
- func DebugE(format string, v ...interface{}) error
- func DebugX(delta int, format string, v ...interface{})
- func Error(format string, v ...interface{})
- func ErrorE(format string, v ...interface{}) error
- func ErrorX(delta int, format string, v ...interface{})
- func Fatal(format string, v ...interface{})
- func FatalE(format string, v ...interface{}) error
- func FatalX(delta int, format string, v ...interface{})
- func GetLevel() int
- func Info(format string, v ...interface{})
- func InfoE(format string, v ...interface{}) error
- func InfoX(delta int, format string, v ...interface{})
- func SetLevel(level int)
- func SetLevelS(level string)
- func TimeLogClose()
- func TimeLogInit(logDir string) error
- func Trace(format string, v ...interface{})
- func TraceE(format string, v ...interface{}) error
- func TraceX(delta int, format string, v ...interface{})
- func Warn(format string, v ...interface{})
- func WarnE(format string, v ...interface{}) error
- func WarnX(delta int, format string, v ...interface{})
- type FileHandler
- type Handler
- type Logger
- func (l *Logger) Buss(format string, v ...interface{})
- func (l *Logger) Close()
- func (l *Logger) Debug(format string, v ...interface{})
- func (l *Logger) Error(format string, v ...interface{})
- func (l *Logger) Fatal(format string, v ...interface{})
- func (l *Logger) Info(format string, v ...interface{})
- func (l *Logger) Level() int
- func (l *Logger) Output(callDepth int, level int, format string, v ...interface{})
- func (l *Logger) SetHandler(h Handler)
- func (l *Logger) SetLevel(level int)
- func (l *Logger) Trace(format string, v ...interface{})
- func (l *Logger) Warn(format string, v ...interface{})
- type NullHandler
- type RotatingFileHandler
- type SocketHandler
- type StreamHandler
- type TimeRollFile
- type TimeRotatingFileHandler
Constants ¶
const ( WhenSecond = iota WhenMinute WhenHour WhenDay )
const ( LevelTrace = iota LevelDebug LevelInfo LevelWarn LevelError LevelFatal LevelBuss )
log level, from low to high, more high means more serious
const ( Ltime = 1 << iota //time format "2006/01/02 15:04:05" Lfile //file.go:123 Llevel //[Trace|Debug|Info...] )
const (
RollTypeDay = iota
)
const TimeFormat = "2006/01/02 15:04:05"
Variables ¶
var LevelName [7]string = [7]string{"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL", "BUSS"}
var LogLevelString = map[string]int{ "trace": LevelTrace, "debug": LevelDebug, "info": LevelInfo, "warn": LevelWarn, "error": LevelError, "fatal": LevelFatal, "buss": LevelBuss, }
var (
TimePrefix = &struct{}{}
)
Functions ¶
func TimeLogClose ¶
func TimeLogClose()
func TimeLogInit ¶
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)
func (*FileHandler) Close ¶
func (h *FileHandler) Close() error
type Logger ¶
func NewDefault ¶
new a default logger with specified handler and flag: Ltime|Lfile|Llevel
func (*Logger) Output ¶
a low interface, maybe you can use it for your special log format but it may be not exported later......
func (*Logger) SetHandler ¶
type NullHandler ¶
type NullHandler struct { }
NullHandler does nothing, it discards anything.
func NewNullHandler ¶
func NewNullHandler() (*NullHandler, error)
func (*NullHandler) Close ¶
func (h *NullHandler) Close() error
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)
func (*RotatingFileHandler) Close ¶
func (h *RotatingFileHandler) Close() error
type SocketHandler ¶
type SocketHandler struct {
// contains filtered or unexported fields
}
SocketHandler writes log to a connectionl. Network protocol is simple: log length + log | log length + log. log length is uint32, bigendian. you must implement your own log server, maybe you can use logd instead simply.
func NewSocketHandler ¶
func NewSocketHandler(protocol string, addr string) (*SocketHandler, error)
func (*SocketHandler) Close ¶
func (h *SocketHandler) Close() error
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)
func (*StreamHandler) Close ¶
func (h *StreamHandler) Close() error
type TimeRollFile ¶
type TimeRollFile struct {
// contains filtered or unexported fields
}
func NewTimeRollFile ¶
func NewTimeRollFile(fileName string, fileDir string, rollTimeType int) *TimeRollFile
func (*TimeRollFile) Close ¶
func (self *TimeRollFile) Close()
func (*TimeRollFile) WriteString ¶
func (self *TimeRollFile) WriteString(logTime int64, content string) error
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)
func (*TimeRotatingFileHandler) Close ¶
func (h *TimeRotatingFileHandler) Close() error