gogogo: github.com/mnhkahn/gogogo/logger Index | Examples | Files

package logger

import "github.com/mnhkahn/gogogo/logger"

A logger package that compatible with sdk log package. It supports level logging and file auto rotating.

It also has a predefined 'standard' Logger called StdLogger accessible through helper functions Debug[f], Info[f], Warn[f], Error[f], LogLevel and SetJack.

It supports 4 level:

LevelError = iota
LevelWarning
LevelInformational
LevelDebug

You can use LogLevel to handle the log level.

File rotating based on package gopkg.in/natefinch/lumberjack.v2, you can control file settings by using SetJack.

Quick start

Use StdLogger:

import "github.com/mnhkahn/gogogo/logger"

logger.Info("hello, world.")

Defined our own logger:

l := logger.NewWriterLogger(w, flag, 3)
l.Info("hello, world")

Log flags compatible with sdk log package, https://golang.org/pkg/log/#pkg-constants.

See also

For more information, goto godoc https://godoc.org/github.com/mnhkahn/gogogo/logger

Chinese details, goto http://blog.cyeam.com//golang/2017/07/14/go-log?utm_source=github

Code:

logger.Info("hello, world.")

Index

Examples

Package Files

doc.go level_logger.go

Constants

const (
    LevelError = iota
    LevelWarning
    LevelInformational
    LevelDebug
)

logger supports 4 levels. Default level is LevelInformational.

Variables

var (
    StdLogger = NewLogger(log.LstdFlags|log.Lshortfile, 3)
)

StdLogger is a predefined logger prints to stdout.

func Debug Uses

func Debug(v ...interface{})

Debug print log with level Debug.

func Debugf Uses

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

Debugf print log with level Debug.

func Error Uses

func Error(v ...interface{})

Error print log with level Error.

func Errorf Uses

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

Errorf print log with level Error.

func GenerateFmtStr Uses

func GenerateFmtStr(n int) string

GenerateFmtStr is a helper function to construct formatter string.

func Info Uses

func Info(v ...interface{})

Info print log with level Info.

func Infof Uses

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

Infof print log with level Info.

func LogLevel Uses

func LogLevel(logLevel string) string

LogLevel sets the log level.

func SetJack Uses

func SetJack(lfn string, maxsize int)

SetJack sets the StdLogger's writer to file lfn.

func Warn Uses

func Warn(v ...interface{})

Warn print log with level Warn.

func Warnf Uses

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

Warnf print log with level Warn.

type Logger Uses

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

Logger ...

func NewFileLogger Uses

func NewFileLogger(lfn string, maxsize int, flag int, depth int) *Logger

NewFileLogger makes a new file logger, it prints to file lfn. File will auto rotate by size maxsize. maxsize is the maximum size in megabytes of the log file

func NewLogger Uses

func NewLogger(flag int, depth int) *Logger

NewLogger makes a new logger prints to stdout.

Code:

w := os.Stdout
flag := log.Llongfile
l := logger.NewWriterLogger(w, flag, 3)
l.Info("hello, world")

func NewLogger2 Uses

func NewLogger2(lfn string, maxsize int, flag int, numWorkers int, jobQueueLen int, depth int) *Logger

Deprecated NewLogger2 use NewFileLogger instead.

func NewLogger3 Uses

func NewLogger3(w io.Writer, flag int, numWorkers int, jobQueueLen int, depth int) *Logger

Deprecated NewLogger3 use NewWriterLogger instead.

func NewWriterLogger Uses

func NewWriterLogger(w io.Writer, flag int, depth int) *Logger

NewWriterLogger makes a new writer file, it prints to writer.

func (*Logger) Debug Uses

func (ll *Logger) Debug(format string, v ...interface{})

Debug print log with level Debug.

func (*Logger) Error Uses

func (ll *Logger) Error(format string, v ...interface{})

Error print log with level Error.

func (*Logger) GetLevel Uses

func (ll *Logger) GetLevel() string

GetLevel gets the current log level name.

func (*Logger) Info Uses

func (ll *Logger) Info(format string, v ...interface{})

Info print log with level Info.

func (*Logger) SetFlag Uses

func (ll *Logger) SetFlag(flag int)

SetFlag sets log flags. For more information, see the sdk https://golang.org/pkg/log/#pkg-constants.

func (*Logger) SetJack Uses

func (ll *Logger) SetJack(lfn string, maxsize int)

SetJack makes logger writes to new file lfn.

func (*Logger) SetLevel Uses

func (ll *Logger) SetLevel(l int) int

SetLevel sets the log level.

func (*Logger) SetPrefix Uses

func (ll *Logger) SetPrefix(prefix string)

SetPrefix set the logger prefix. Default prefix is [D] for Debug, [I] for Info, [W] for Warn and [E] for Error.

func (*Logger) Warn Uses

func (ll *Logger) Warn(format string, v ...interface{})

Warn print log with level Warn.

Package logger imports 6 packages (graph) and is imported by 3 packages. Updated 2018-09-03. Refresh now. Tools for package owners.