logging

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2022 License: MIT Imports: 15 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

This section is empty.

Functions

func Debug

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

Debug print debug log

func Error

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

Error print error log

func Flush

func Flush()

Flush flush log

func Info

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

Info print info log

func Printf

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

Printf print log by format

func Println

func Println(v ...interface{})

Println print log from values

func SetDateRotate

func SetDateRotate(cfg DateRotateConfig)

SetDateRotate set log rotate by date

func SetSizeRotate

func SetSizeRotate(cfg SizeRotateConfig)

SetSizeRotate set log rotate by size

func Warning

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

Warning print warning log

Types

type DateRotateConfig

type DateRotateConfig struct {
	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 Logger

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

Logger logger interface

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

DefaultLogger default logger by log package

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{})

Debug print debug log

func (*Logger) Error

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

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{})

Info print info log

func (*Logger) Printf

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

Printf print log with format

func (*Logger) Warning

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

Warning print warning log

func (*Logger) Write

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

Write write log

type SizeRotateConfig

type SizeRotateConfig struct {
	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