logging

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: MIT Imports: 14 Imported by: 6

Documentation

Overview

log library supported loglevel and logrotate.

loglevel:

Debug: 1‰ probability to write log with format [DEBUG]...
Info: write info log with format [INFO]...
Warning: write warning log with format [WARNING]...
Error: write error log with stacktrace and format [ERROR]...

logrotate:

date: it will rename the log file to <name>_<yyyymmdd>.log in the next day.
size: it will rename the log file to <name>.log.<n> when log size is more than limit size.

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogger = Logger{
	// contains filtered or unexported fields
}

DefaultLogger default logger by log package

Functions

func Debug

func Debug(fmt string, a ...interface{}) string

Debug print debug log

func Error

func Error(fmt string, a ...interface{}) string

Error print error log

func Files added in v1.3.0

func Files() []string

Files get log files

func Flush

func Flush()

Flush flush log

func Info

func Info(fmt string, a ...interface{}) string

Info print info log

func Printf

func Printf(fmt string, a ...interface{}) string

Printf print log by format

func Println

func Println(v ...interface{}) string

Println print log from values

func SetDateRotate

func SetDateRotate(cfg DateRotateConfig)

SetDateRotate set log rotate by date

func SetLevel added in v1.5.0

func SetLevel(level Level)

SetLevel set log level

func SetSizeRotate

func SetSizeRotate(cfg SizeRotateConfig)

SetSizeRotate set log rotate by size

func Warning

func Warning(fmt string, a ...interface{}) string

Warning print warning log

Types

type DateRotateConfig

type DateRotateConfig struct {
	Level       Level  // log level
	Dir         string // log file save directory, only used if WriteFile=true
	Name        string // log file name, only used if WriteFile=true
	Rotate      int    // save rotated file count, only used if WriteFile=true
	WriteStdout bool   // allow write to stdout
	WriteFile   bool   // allow write to file
}

DateRotateConfig date logger config

type Level added in v1.5.0

type Level int
const (
	LevelDebug Level = iota
	LevelInfo
	LevelWarn
	LevelError
)

type Logger

type Logger struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Logger logger interface

func NewRotateDateLogger

func NewRotateDateLogger(cfg DateRotateConfig) Logger

NewRotateDateLogger create logger by date rotate

func NewRotateSizeLogger

func NewRotateSizeLogger(cfg SizeRotateConfig) Logger

NewRotateSizeLogger create logger rotate by file size

func (*Logger) Debug

func (l *Logger) Debug(fmt string, a ...interface{}) string

Debug print debug log

func (*Logger) Error

func (l *Logger) Error(fmt string, a ...interface{}) string

Error print error log

func (*Logger) Flush

func (l *Logger) Flush()

Flush flush log

func (*Logger) Info

func (l *Logger) Info(fmt string, a ...interface{}) string

Info print info log

func (*Logger) Printf

func (l *Logger) Printf(fmt string, a ...interface{}) string

Printf print log with format

func (*Logger) Warning

func (l *Logger) Warning(fmt string, a ...interface{}) string

Warning print warning log

func (*Logger) Write

func (l *Logger) Write(data []byte) (int, error)

Write write log

type SizeRotateConfig

type SizeRotateConfig struct {
	Level       Level  // log level
	Dir         string // log file save directory, only used if WriteFile=true
	Name        string // log file name, only used if WriteFile=true
	Size        int64  // rotate when file >= Size, only used if WriteFile=true
	Rotate      int    // save rotated file count, only used if WriteFile=true
	WriteStdout bool   // allow write to stdout
	WriteFile   bool   // allow write to file
}

SizeRoateConfig size logger config

Jump to

Keyboard shortcuts

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