log

package module
v0.0.0-...-932be1f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2022 License: MIT Imports: 22 Imported by: 0

README

glog

Simple log package for golang

Documentation

Index

Constants

View Source
const (
	RotateByDuration = "RotateByDuration"
	RotateBySize     = "RotateBySize"

	SweepByFileCount = "SweepByFileCount"
	SweepByInterval  = "SweepByInterval"

	DefaultRotatePolicy   = RotateByDuration
	DefaultSweepPolicy    = SweepByFileCount
	DefaultRotateFileSize = 50 << 20           // rotate log file every 50M
	DefaultRotateDuration = 24 * time.Hour     // rotate log file every 24 hours
	DefaultSweepInterval  = 7 * 24 * time.Hour // sweep log file 7 days before
	DefaultSweepFileCount = 5
)
View Source
const (
	ModeRelease = "release"
	ModeDebug   = "debug"
)
View Source
const (
	Console = "console"
	File    = "file"
	Syslog  = "syslog"
)
View Source
const (
	BufferCapacity = 8
)

Capacity of buffer channel

Variables

This section is empty.

Functions

func Close

func Close()

Close closes log engine

func Debug

func Debug(args ...interface{})

Debug print debug message

func Error

func Error(args ...interface{})

Error print error message

func Fatal

func Fatal(args ...interface{})

Fatal print fatal error message, and app will quit if this function called

func Info

func Info(args ...interface{})

Info print information message

func Panic

func Panic(args ...interface{})

Panic print panic message, and app will trigger panic message if called

func Regist

func Regist(logger Logger)

Regist adds a logger, Log package default add one logger(console), means default all the log message will print to console. But you can use this function to add new logger to log engine.

func SetFormatter

func SetFormatter(logger string, formatter Formatter) error

func SetMode

func SetMode(mode string)

func Trace

func Trace(args ...interface{})

Trace print trace message, which prints more details

func Verbose

func Verbose(args ...interface{})

func Warning

func Warning(args ...interface{})

Warning print warning message

Types

type Fields

type Fields map[string]interface{}

func (Fields) Debug

func (f Fields) Debug(args ...interface{})

func (Fields) Error

func (f Fields) Error(args ...interface{})

func (Fields) Fatal

func (f Fields) Fatal(args ...interface{})

func (Fields) Info

func (f Fields) Info(args ...interface{})

func (Fields) Panic

func (f Fields) Panic(args ...interface{})

func (Fields) Trace

func (f Fields) Trace(args ...interface{})

func (Fields) Verbose

func (f Fields) Verbose(args ...interface{})

func (Fields) Warning

func (f Fields) Warning(args ...interface{})

type Formatter

type Formatter interface {
	Format(*Message) string
}

type JSONFormatter

type JSONFormatter struct{}

func (*JSONFormatter) Format

func (jf *JSONFormatter) Format(msg *Message) string

type Level

type Level uint8
const (
	LevelPanic Level = iota
	LevelFatal
	LevelError
	LevelWarn
	LevelInfo
	LevelVerbose
	LevelDebug
	LevelTrace
)

Log level

func (Level) MarshalJSON

func (l Level) MarshalJSON() ([]byte, error)

func (Level) String

func (l Level) String() string

func (Level) Tag

func (l Level) Tag() string

type Logger

type Logger interface {
	// Name returns logger's name
	Name() string
	// Level returns logger's level
	Level() Level
	// Write writes a message to logger
	Write(msg *Message)
	// Close closes a logger
	Close() error
}

Logger interface, all supported logger MUST implement this interface

func NewConsoleLogger

func NewConsoleLogger(level Level, options ...Option) Logger

NewConsoleLogger creates a new console logger

func NewFileLogger

func NewFileLogger(level Level, options ...Option) Logger

NewFileLogger creates a file logger implementation

func NewSysLogger

func NewSysLogger(level Level, address string, options ...Option) Logger

type Message

type Message struct {
	Level     Level     `json:"level"`
	Filename  string    `json:"filename,omitempty"`
	Function  string    `json:"function,omitempty"`
	Line      int       `json:"line,omitempty"`
	Message   string    `json:"message"`
	Timestamp time.Time `json:"timestamp"`
	Fields    Fields    `json:"-"`
}

Message represents Log message record, minimal log dispatch unit

type Option

type Option func(Logger)

func Colorful

func Colorful() Option

func Path

func Path(path string, patterns ...string) Option

func RotateDuration

func RotateDuration(duration time.Duration) Option

func RotateFileSize

func RotateFileSize(size int64) Option

func RotatePolicy

func RotatePolicy(policy string) Option

func SweepFileCount

func SweepFileCount(count int) Option

func SweepInterval

func SweepInterval(interval time.Duration) Option

func SweepPolicy

func SweepPolicy(policy string) Option

type TextFormatter

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

func (*TextFormatter) Format

func (tf *TextFormatter) Format(msg *Message) (message string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL