go-log: github.com/siddontang/go-log/log Index | Files

package log

import "github.com/siddontang/go-log/log"

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/siddontang/go-log/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

Package Files

doc.go filehandler.go handler.go log.go logger.go

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

func Debug Uses

func Debug(args ...interface{})

Debug records the log with debug level

func DebugJson Uses

func DebugJson(body interface{})

Debug records the log with debug level

func Debugf Uses

func Debugf(format string, args ...interface{})

Debugf records the log with debug level

func Debugln Uses

func Debugln(args ...interface{})

Debugln records the log with debug level

func Error Uses

func Error(args ...interface{})

Error records the log with error level

func ErrorJson Uses

func ErrorJson(body interface{})

Error records the log with error level

func Errorf Uses

func Errorf(format string, args ...interface{})

Errorf records the log with error level

func Errorln Uses

func Errorln(args ...interface{})

Errorln records the log with error level

func Fatal Uses

func Fatal(args ...interface{})

Fatal records the log with fatal level and exits

func Fatalf Uses

func Fatalf(format string, args ...interface{})

Fatalf records the log with fatal level and exits

func Fatalln Uses

func Fatalln(args ...interface{})

Fatalln records the log with fatal level and exits

func Info Uses

func Info(args ...interface{})

Info records the log with info level

func InfoJson Uses

func InfoJson(body interface{})

Info records the log with info level by json format

func Infof Uses

func Infof(format string, args ...interface{})

Infof records the log with info level

func Infoln Uses

func Infoln(args ...interface{})

Infoln records the log with info level

func Panic Uses

func Panic(args ...interface{})

Panic records the log with fatal level and panics

func Panicf Uses

func Panicf(format string, args ...interface{})

Panicf records the log with fatal level and panics

func Panicln Uses

func Panicln(args ...interface{})

Panicln records the log with fatal level and panics

func Print Uses

func Print(args ...interface{})

Print records the log with trace level

func PrintJson Uses

func PrintJson(body interface{})

Print records the log with trace level

func Printf Uses

func Printf(format string, args ...interface{})

Printf records the log with trace level

func Println Uses

func Println(args ...interface{})

Println records the log with trace level

func SetDefaultLogger Uses

func SetDefaultLogger(l *Logger)

SetDefaultLogger changes the global logger

func SetLevel Uses

func SetLevel(level Level)

SetLevel changes the logger level

func SetLevelByName Uses

func SetLevelByName(name string)

SetLevelByName changes the logger level by name

func Warn Uses

func Warn(args ...interface{})

Warn records the log with warn level

func Warnf Uses

func Warnf(format string, args ...interface{})

Warnf records the log with warn level

func Warnln Uses

func Warnln(args ...interface{})

Warnln records the log with warn level

type FileHandler Uses

type FileHandler struct {
    // contains filtered or unexported fields
}

FileHandler writes log to a file.

func NewFileHandler Uses

func NewFileHandler(fileName string, flag int) (*FileHandler, error)

NewFileHandler creates a FileHander

func (*FileHandler) Close Uses

func (h *FileHandler) Close() error

Close implements Handler interface

func (*FileHandler) Write Uses

func (h *FileHandler) Write(b []byte) (n int, err error)

Write implements Handler interface

type Handler Uses

type Handler interface {
    Write(p []byte) (n int, err error)
    Close() error
}

Handler writes logs to somewhere

type Level Uses

type Level int

Level type

const (
    LevelTrace Level = iota
    LevelDebug
    LevelInfo
    LevelWarn
    LevelError
    LevelFatal
)

Log level, from low to high, more high means more serious

func (Level) String Uses

func (l Level) String() string

String returns level String

type Logger Uses

type Logger struct {
    // TODO: support logger.Contextual
    loggers.Advanced
    // contains filtered or unexported fields
}

Logger is the logger to record log

func New Uses

func New(handler Handler, flag int) *Logger

New creates a logger with specified handler and flag

func NewDefault Uses

func NewDefault(handler Handler) *Logger

NewDefault creates default logger with specified handler and flag: Ltime|Lfile|Llevel

func (*Logger) Close Uses

func (l *Logger) Close()

Close closes the logger

func (*Logger) Debug Uses

func (l *Logger) Debug(args ...interface{})

Debug records the log with debug level

func (*Logger) Debugf Uses

func (l *Logger) Debugf(format string, args ...interface{})

Debugf records the log with debug level

func (*Logger) Debugln Uses

func (l *Logger) Debugln(args ...interface{})

Debugln records the log with debug level

func (*Logger) Error Uses

func (l *Logger) Error(args ...interface{})

Error records the log with error level

func (*Logger) Errorf Uses

func (l *Logger) Errorf(format string, args ...interface{})

Errorf records the log with error level

func (*Logger) Errorln Uses

func (l *Logger) Errorln(args ...interface{})

Errorln records the log with error level

func (*Logger) Fatal Uses

func (l *Logger) Fatal(args ...interface{})

Fatal records the log with fatal level and exits

func (*Logger) Fatalf Uses

func (l *Logger) Fatalf(format string, args ...interface{})

Fatalf records the log with fatal level and exits

func (*Logger) Fatalln Uses

func (l *Logger) Fatalln(args ...interface{})

Fatalln records the log with fatal level and exits

func (*Logger) Info Uses

func (l *Logger) Info(args ...interface{})

Info records the log with info level

func (*Logger) Infof Uses

func (l *Logger) Infof(format string, args ...interface{})

Infof records the log with info level

func (*Logger) Infoln Uses

func (l *Logger) Infoln(args ...interface{})

Infoln records the log with info level

func (*Logger) Output Uses

func (l *Logger) Output(callDepth int, level Level, msg string)

Output records the log with special callstack depth and log level.

func (*Logger) OutputJson Uses

func (l *Logger) OutputJson(callDepth int, level Level, body interface{})

Output json format records the log with special callstack depth and log level.

func (*Logger) Panic Uses

func (l *Logger) Panic(args ...interface{})

Panic records the log with fatal level and panics

func (*Logger) Panicf Uses

func (l *Logger) Panicf(format string, args ...interface{})

Panicf records the log with fatal level and panics

func (*Logger) Panicln Uses

func (l *Logger) Panicln(args ...interface{})

Panicln records the log with fatal level and panics

func (*Logger) Print Uses

func (l *Logger) Print(args ...interface{})

Print records the log with trace level

func (*Logger) Printf Uses

func (l *Logger) Printf(format string, args ...interface{})

Printf records the log with trace level

func (*Logger) Println Uses

func (l *Logger) Println(args ...interface{})

Println records the log with trace level

func (*Logger) SetLevel Uses

func (l *Logger) SetLevel(level Level)

SetLevel sets log level, any log level less than it will not log

func (*Logger) SetLevelByName Uses

func (l *Logger) SetLevelByName(name string)

SetLevelByName sets log level by name

func (*Logger) Warn Uses

func (l *Logger) Warn(args ...interface{})

Warn records the log with warn level

func (*Logger) Warnf Uses

func (l *Logger) Warnf(format string, args ...interface{})

Warnf records the log with warn level

func (*Logger) Warnln Uses

func (l *Logger) Warnln(args ...interface{})

Warnln records the log with warn level

type NullHandler Uses

type NullHandler struct {
}

NullHandler does nothing, it discards anything.

func NewNullHandler Uses

func NewNullHandler() (*NullHandler, error)

NewNullHandler creates a NullHandler

func (*NullHandler) Close Uses

func (h *NullHandler) Close() error

Close implements Handler interface

func (*NullHandler) Write Uses

func (h *NullHandler) Write(b []byte) (n int, err error)

// Write implements Handler interface

type RotatingFileHandler Uses

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 Uses

func NewRotatingFileHandler(fileName string, maxBytes int, backupCount int) (*RotatingFileHandler, error)

NewRotatingFileHandler creates a RotatingFileHandler

func (*RotatingFileHandler) Close Uses

func (h *RotatingFileHandler) Close() error

Close implements Handler interface

func (*RotatingFileHandler) Write Uses

func (h *RotatingFileHandler) Write(p []byte) (n int, err error)

Write implements Handler interface

type StreamHandler Uses

type StreamHandler struct {
    // contains filtered or unexported fields
}

StreamHandler writes logs to a specified io Writer, maybe stdout, stderr, etc...

func NewStreamHandler Uses

func NewStreamHandler(w io.Writer) (*StreamHandler, error)

NewStreamHandler creates a StreamHandler

func (*StreamHandler) Close Uses

func (h *StreamHandler) Close() error

Close implements Handler interface

func (*StreamHandler) Write Uses

func (h *StreamHandler) Write(b []byte) (n int, err error)

Write implements Handler interface

type TimeRotatingFileHandler Uses

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 Uses

func NewTimeRotatingFileHandler(baseName string, when int8, interval int) (*TimeRotatingFileHandler, error)

NewTimeRotatingFileHandler creates a TimeRotatingFileHandler

func (*TimeRotatingFileHandler) Close Uses

func (h *TimeRotatingFileHandler) Close() error

Close implements Handler interface

func (*TimeRotatingFileHandler) Write Uses

func (h *TimeRotatingFileHandler) Write(b []byte) (n int, err error)

Write implements Handler interface

Package log imports 11 packages (graph) and is imported by 32 packages. Updated 2019-03-01. Refresh now. Tools for package owners.