Documentation ¶
Overview ¶
Package log is an alternative to log package in standard library.
Index ¶
- Variables
- func Critical(args ...interface{})
- func Criticalf(format string, args ...interface{})
- func Criticalln(args ...interface{})
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func Debugln(args ...interface{})
- func Error(args ...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 Infof(format string, args ...interface{})
- func Infoln(args ...interface{})
- func Notice(args ...interface{})
- func Noticef(format string, args ...interface{})
- func Noticeln(args ...interface{})
- func Panic(args ...interface{})
- func Panicf(format string, args ...interface{})
- func Panicln(args ...interface{})
- func SetLevel(l Level)
- func Warning(args ...interface{})
- func Warningf(format string, args ...interface{})
- func Warningln(args ...interface{})
- type BaseHandler
- type Color
- type FileHandler
- type Formatter
- type Handler
- type Level
- type Logger
- type MultiHandler
- type Record
- type SyslogHandler
- type WriterHandler
Constants ¶
This section is empty.
Variables ¶
var ( DefaultLogger Logger = NewLogger(procName) DefaultLevel Level = INFO DefaultHandler Handler = NewFileHandler(os.Stderr) DefaultFormatter Formatter = defaultFormatter{} )
Functions ¶
func Criticalln ¶
func Criticalln(args ...interface{})
Types ¶
type BaseHandler ¶
func NewBaseHandler ¶
func NewBaseHandler() *BaseHandler
func (*BaseHandler) FilterAndFormat ¶
func (h *BaseHandler) FilterAndFormat(rec *Record) string
func (*BaseHandler) SetFormatter ¶
func (h *BaseHandler) SetFormatter(f Formatter)
func (*BaseHandler) SetLevel ¶
func (h *BaseHandler) SetLevel(l Level)
type FileHandler ¶
type FileHandler struct { *BaseHandler // contains filtered or unexported fields }
FileHandler is a handler implementation that writes the logging output to a *os.File. If given file is a tty, output will be colored.
func NewFileHandler ¶
func NewFileHandler(f *os.File) *FileHandler
func (*FileHandler) Close ¶
func (h *FileHandler) Close() error
func (*FileHandler) Handle ¶
func (h *FileHandler) Handle(rec *Record)
type Formatter ¶
type Formatter interface { // Format the record and return a message. Format(*Record) (message string) }
Formatter formats a record.
type Handler ¶
type Handler interface { SetFormatter(Formatter) SetLevel(Level) // Handle single log record. Handle(*Record) // Close the handler. Close() error }
Handler handles the output.
type Logger ¶
type Logger interface { // SetLevel changes the level of the logger. Default is logging.Info. SetLevel(Level) // SetHandler replaces the current handler for output. Default is logging.StderrHandler. SetHandler(Handler) // SetCallDepth sets the parameter passed to runtime.Caller(). // It is used to get the file name from call stack. // For example you need to set it to 1 if you are using a wrapper around // the Logger. Default value is zero. SetCallDepth(int) // Fatal is equivalent to Logger.Critical followed by a call to os.Exit(1). Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) Fatalln(args ...interface{}) // Panic is equivalent to Logger.Critical followed by a call to panic(). Panic(args ...interface{}) Panicf(format string, args ...interface{}) Panicln(args ...interface{}) // Log functions Critical(args ...interface{}) Criticalf(format string, args ...interface{}) Criticalln(args ...interface{}) Error(args ...interface{}) Errorf(format string, args ...interface{}) Errorln(args ...interface{}) Warning(args ...interface{}) Warningf(format string, args ...interface{}) Warningln(args ...interface{}) Notice(args ...interface{}) Noticef(format string, args ...interface{}) Noticeln(args ...interface{}) Info(args ...interface{}) Infof(format string, args ...interface{}) Infoln(args ...interface{}) Debug(args ...interface{}) Debugf(format string, args ...interface{}) Debugln(args ...interface{}) }
Logger is the interface for outputing log messages in different levels. A new Logger can be created with NewLogger() function. You can changed the output handler with SetHandler() function.
type MultiHandler ¶
type MultiHandler struct {
// contains filtered or unexported fields
}
MultiHandler sends the log output to multiple handlers concurrently.
func NewMultiHandler ¶
func NewMultiHandler(handlers ...Handler) *MultiHandler
func (*MultiHandler) Close ¶
func (b *MultiHandler) Close() error
func (*MultiHandler) Handle ¶
func (b *MultiHandler) Handle(rec *Record)
func (*MultiHandler) SetFormatter ¶
func (b *MultiHandler) SetFormatter(f Formatter)
func (*MultiHandler) SetLevel ¶
func (b *MultiHandler) SetLevel(l Level)
type Record ¶
type Record struct { Message string // Formatted log message LoggerName string // Name of the logger module Level Level // Level of the record Time time.Time // Time of the record (local time) Filename string // File name of the log call (absolute path) Line int // Line number in file ProcessID int // PID ProcessName string // Name of the process }
Record contains all of the information about a single log message.
type SyslogHandler ¶
type SyslogHandler struct { *BaseHandler // contains filtered or unexported fields }
SyslogHandler sends the logging output to syslog.
func NewSyslogHandler ¶
func NewSyslogHandler(tag string) (*SyslogHandler, error)
func NewSyslogHandlerDial ¶
func NewSyslogHandlerDial(network, raddr, tag string) (*SyslogHandler, error)
func (*SyslogHandler) Close ¶
func (b *SyslogHandler) Close() error
func (*SyslogHandler) Handle ¶
func (b *SyslogHandler) Handle(rec *Record)
type WriterHandler ¶
type WriterHandler struct { *BaseHandler // contains filtered or unexported fields }
WriterHandler is a handler implementation that writes the logging output to a io.Writer.
func NewWriterHandler ¶
func NewWriterHandler(w io.Writer) *WriterHandler
func (*WriterHandler) Close ¶
func (b *WriterHandler) Close() error
func (*WriterHandler) Handle ¶
func (b *WriterHandler) Handle(rec *Record)