wlog

package module
v1.3.14 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

README

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

wlog is a structured logger for Go (golang), completely API compatible with the standard library logger. Support scheduled task log rotation.
markdown »

Demo · Bug · Issues

English | 中文

Guide

  1. Use Debug、Info、Warn、Error、Fatal、Panic
wlog.Debug("test message")
wlog.Info("test message")
wlog.Warn("test message")
wlog.Error("test message")
wlog.Fatal("test message")
wlog.Panic("test message")
  1. library log
wlog.Print("test message")
wlog.Println("test message")
wlog.Printf("%s","test message")

wlog.Painc("test message")
wlog.Paincln("test message")
wlog.Paincf("%s","test message")
  1. Custom configuration of other item data
log := wlog.New()
log.Console()
log.WithKeys("key1", "key2", "key3")
for i := 1; i < 100; i++ {
log.InfoValues(i+1, i+2, i+3)
}
  1. Custom output format (default text format)
l := wlog.New()
l.Json() // l.Text()
l.Info("test message")
  1. cron rotate log
log := wlog.NewLogConfig(InfoLevel, false, 0, false, wlog.NewFileCycle("info", wlog.DayCycle, "* * * * * *"), wlog.NewFormatJson())
for i := 0; i < 1000000; i++ {
    log.WithField("item", strconv.Itoa(i))
    log.Println(i)
}
  1. Caller Frame
  • print caller Frame information
l := wlog.New()
l.CallFrame()
l.Info("test message")
  • print error information
// a.log
err := errors.New("error test")
Err(err)
//b.log
l := wlog.New()
l.CallFrameDepth() // call FrameDepth depth +1 
func Err(err error){
    ir err!=nil {
        l.error()
    }
}

  1. Output
level="error"	 time="2024-**-** 13:24:03"	field="value"	file="D:/**/go/src/testing/testing.go"	func="testing.tRunner"	key="value"	line="1595"	
{"error":"this log level is info, not call debug()","field":"value","file":"D:/**/go/src/testing/testing.go","func":"testing.tRunner","key":"value","level":"error","line":1595,"time":"2024-**-** 13:30:47"}
Pre development Configuration Requirements
  1. go version 1.21.1
Installation
  1. go get github.com/learnselfs/wlog github.com/learnselfs/wlog

Contributor

Please read CONTABUTING.md to find out the developers who have contributed to this project.

Open Source Projects

Contributing makes the open source community an excellent place to learn, motivate, and create. Any contribution you make is greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project has signed an Apache license, please refer to for details. LICENSE

Thanks

Documentation

Overview

Package wlog @Author Bing @Date 2024/2/21 16:18:00 @Desc

Package wlog @Author Bing @Date 2024/8/14 17:12:00 @Desc

Package wlog @Author Bing @Date 2024/2/21 18:29:00 @Desc

Package wlog @Author Bing @Date 2024/8/12 15:16:00 @Desc

Package wlog @Author Bing @Date 2024/2/22 16:32:00 @Desc

Package wlog @Author Bing @Date 2024/2/25 19:26:00 @Desc

Package wlog @Author Bing @Date 2024/2/27 15:57:00 @Desc

Package wlog @Author Bing @Date 2024/2/21 16:34:00 @Desc

Package wlog @Author Bing @Date 2024/2/2 15:38:00 @Desc

Package wlog @Author Bing @Date 2024/2/22 17:18:00 @Desc

Package wlog @Author Bing @Date 2024/2/22 15:13:00 @Desc

Index

Constants

View Source
const (
	DebugLevel Level = iota
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
	PanicLevel

	Timestamp string = "time"
	LogLevel  string = "level"
	Message   string = "message"
	Errors    string = "error"
	CallFile  string = "file"
	CallFunc  string = "func"
	CallLine  string = "line"
)

Variables

View Source
var (
	Cron *cron
)

Functions

func CallFrame added in v1.2.13

func CallFrame()

func CallFramesDepth added in v1.2.13

func CallFramesDepth(depths ...int)

func Debug

func Debug(msg string)

func DebugValues added in v1.3.14

func DebugValues(values ...any)

func Debugf added in v1.2.11

func Debugf(f string, msg ...any)

func Debugln added in v1.2.12

func Debugln(msg ...any)

func Error

func Error(msg string)

func ErrorValues added in v1.3.14

func ErrorValues(values ...any)

func Errorf added in v1.2.11

func Errorf(f string, msg ...any)

func Errorln added in v1.2.12

func Errorln(msg ...any)

func Fatal added in v1.2.2

func Fatal(msg string)

func FatalValues added in v1.3.14

func FatalValues(values ...any)

func Fatalf added in v1.2.11

func Fatalf(f string, msg ...any)

func Fatalln added in v1.2.12

func Fatalln(msg ...any)

func Info

func Info(msg string)

func InfoValues added in v1.3.14

func InfoValues(values ...any)

func Infof added in v1.2.11

func Infof(f string, msg ...any)

func Infoln added in v1.2.12

func Infoln(msg ...any)

func Json added in v1.2.13

func Json()

func Panic added in v1.2.2

func Panic(msg string)

func PanicValues added in v1.3.14

func PanicValues(values ...any)

func Panicf added in v1.2.11

func Panicf(f string, msg ...any)

func Panicln added in v1.2.2

func Panicln(msg ...any)

func Parser added in v1.2.13

func Parser(express string, handle func() error) (*cronTask, error)

func Print added in v1.2.2

func Print(msg string)

func Printf added in v1.2.2

func Printf(f string, msg ...any)

func Println added in v1.2.2

func Println(msg ...any)

func Text added in v1.2.13

func Text()

func Values added in v1.3.14

func Values(values ...any)

func Warn added in v1.2.2

func Warn(msg string)

func Warnf added in v1.2.11

func Warnf(f string, msg ...any)

func Warnln added in v1.2.12

func Warnln(msg ...any)

func WithField added in v1.3.14

func WithField(key string, value any)

func WithFields added in v1.3.14

func WithFields(fields map[string]any)

func WithKeys added in v1.3.14

func WithKeys(kes ...string)

Types

type BufferPool added in v1.1.0

type BufferPool interface {
	Get() *bytes.Buffer
	Set(*bytes.Buffer)
}

BufferPool interface

type Cycle added in v1.2.13

type Cycle int
const (
	SecondCycle Cycle = iota
	MinuteCycle
	HourCycle
	DayCycle
	MonthCycle
	WeekCycle
)

type DefaultBufferPool added in v1.1.0

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

func (*DefaultBufferPool) Get added in v1.1.0

func (p *DefaultBufferPool) Get() *bytes.Buffer

func (*DefaultBufferPool) Set added in v1.1.0

func (p *DefaultBufferPool) Set(b *bytes.Buffer)

type DefaultEntryPool added in v1.1.0

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

func (*DefaultEntryPool) Get added in v1.1.0

func (d *DefaultEntryPool) Get() *Entry

func (*DefaultEntryPool) Set added in v1.1.0

func (d *DefaultEntryPool) Set(e *Entry)

type Entry added in v1.1.0

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

func NewEntry added in v1.1.0

func NewEntry(log *Log) *Entry

func (*Entry) CallFrame added in v1.2.13

func (e *Entry) CallFrame(depth int) *runtime.Frame

func (*Entry) Cron added in v1.2.13

func (e *Entry) Cron(express string)

Cron linux cron task express: example:

"* * * * * *"

func (*Entry) Debug added in v1.1.0

func (e *Entry) Debug(msg string)

func (*Entry) Dup added in v1.1.0

func (e *Entry) Dup() *Entry

func (*Entry) Error added in v1.1.0

func (e *Entry) Error(msg string)

func (*Entry) Fatal added in v1.1.0

func (e *Entry) Fatal(msg string)

func (*Entry) Info added in v1.1.0

func (e *Entry) Info(msg string)

func (*Entry) Log added in v1.1.0

func (e *Entry) Log(level Level, msg string)

func (*Entry) Panic added in v1.2.2

func (e *Entry) Panic(msg string)

func (*Entry) Warn added in v1.1.0

func (e *Entry) Warn(msg string)

type EntryPool added in v1.1.0

type EntryPool interface {
	Get() *Entry
	Set(*Entry)
}

EntryPool interface

type Fields added in v1.1.0

type Fields map[string]interface{}

Fields entry data type

type File added in v1.2.13

type File struct {
	Name    string
	Postfix string

	// file destination path
	Path string
	// file size byte
	Max  float64
	Size float64
	// number of file backup
	Number int
	// cycle
	Cycle      Cycle
	Expression string
	// contains filtered or unexported fields
}

func NewFile added in v1.2.13

func NewFile(name, path string, max, size float64, number int, cycle Cycle, expression string) *File

func NewFileCycle added in v1.2.13

func NewFileCycle(name string, cycle Cycle, expression string) *File

func NewFileInfo added in v1.2.13

func NewFileInfo() *File

func NewFileName added in v1.2.13

func NewFileName(name string, cycle Cycle) *File

func NewFileTest added in v1.2.13

func NewFileTest() *File

func (*File) Rotate added in v1.2.13

func (f *File) Rotate() error

func (*File) Write added in v1.2.13

func (f *File) Write(data []byte) error

Write log to file

type JsonFormat added in v1.1.0

type JsonFormat struct {
	TimeFormat string // time format

	DisableTime  bool
	DisableLevel bool
	DisableColor bool
}

func NewFormatJson added in v1.2.13

func NewFormatJson() *JsonFormat

func (*JsonFormat) Format added in v1.1.0

func (j *JsonFormat) Format(entry *Entry) ([]byte, error)

func (*JsonFormat) Parse added in v1.1.0

func (j *JsonFormat) Parse(e *Entry) Fields

type Level added in v1.1.0

type Level int

func (Level) Marshal added in v1.2.2

func (l Level) Marshal() (string, error)

func (Level) MarshalColor added in v1.2.5

func (l Level) MarshalColor() (string, error)

type Log added in v1.1.0

type Log struct {

	// format
	Format ReportFormat // log output format : json/text

	// file
	*File
	// contains filtered or unexported fields
}

func New added in v1.1.0

func New() *Log

func NewEntryPool added in v1.1.0

func NewEntryPool(l *Log) *Log

func NewLog added in v1.2.13

func NewLog(level Level, file *File, format ReportFormat) *Log

NewLog create info logger

func NewLogConfig added in v1.2.13

func NewLogConfig(level Level, callFrame bool, callFrameDepth int, isOutput bool, output io.Writer, file *File, format ReportFormat) *Log

NewLogConfig create default logger

func NewLogInfoJson added in v1.2.13

func NewLogInfoJson() *Log

func (*Log) CallFrame added in v1.2.13

func (l *Log) CallFrame()

func (*Log) CallFramesDepth added in v1.2.13

func (l *Log) CallFramesDepth(depths ...int)

func (*Log) Console added in v1.2.13

func (l *Log) Console()

Console enable default console output log

func (*Log) Debug added in v1.1.0

func (l *Log) Debug(msg string)

func (*Log) DebugValues added in v1.3.14

func (l *Log) DebugValues(values ...any)

func (*Log) Debugf added in v1.2.6

func (l *Log) Debugf(format string, msg ...any)

func (*Log) Debugln added in v1.2.12

func (l *Log) Debugln(msg ...any)

func (*Log) Error added in v1.1.0

func (l *Log) Error(msg string)

func (*Log) ErrorValues added in v1.3.14

func (l *Log) ErrorValues(values ...any)

func (*Log) Errorf added in v1.2.6

func (l *Log) Errorf(format string, msg ...any)

func (*Log) Errorln added in v1.2.12

func (l *Log) Errorln(msg ...any)

func (*Log) Fatal added in v1.1.0

func (l *Log) Fatal(msg string)

func (*Log) FatalValues added in v1.3.14

func (l *Log) FatalValues(values ...any)

func (*Log) Fatalf added in v1.2.2

func (l *Log) Fatalf(format string, msg ...any)

func (*Log) Fatalln added in v1.2.2

func (l *Log) Fatalln(msg ...any)

func (*Log) Formatter added in v1.2.13

func (l *Log) Formatter(f ReportFormat)

Formatter custom log formatter

func (*Log) Info added in v1.1.0

func (l *Log) Info(msg string)

func (*Log) InfoValues added in v1.3.14

func (l *Log) InfoValues(values ...any)

func (*Log) Infof added in v1.2.6

func (l *Log) Infof(format string, msg ...any)

func (*Log) Infoln added in v1.2.12

func (l *Log) Infoln(msg ...any)

func (*Log) Json added in v1.2.13

func (l *Log) Json()

Json SetJsonFormat define log output format

func (*Log) JsonColorDisable added in v1.2.13

func (l *Log) JsonColorDisable(timeFormat string)

func (*Log) JsonFormatDetail added in v1.2.13

func (l *Log) JsonFormatDetail(timeFormat string, disableTime, disableColor, disableLevel bool)

func (*Log) JsonTime added in v1.2.13

func (l *Log) JsonTime(timeFormat string)

func (*Log) JsonTimeDisable added in v1.2.13

func (l *Log) JsonTimeDisable()

func (*Log) Level added in v1.2.13

func (l *Log) Level(level Level) bool

func (*Log) Output added in v1.2.13

func (l *Log) Output(output io.Writer)

func (*Log) Panic added in v1.2.2

func (l *Log) Panic(msg string)

func (*Log) PanicValues added in v1.3.14

func (l *Log) PanicValues(values ...any)

func (*Log) Panicf added in v1.2.2

func (l *Log) Panicf(format string, msg ...any)

func (*Log) Panicln added in v1.2.2

func (l *Log) Panicln(msg ...any)

func (*Log) Print added in v1.2.2

func (l *Log) Print(msg string)

func (*Log) Printf added in v1.2.2

func (l *Log) Printf(f string, msg ...any)

func (*Log) Println added in v1.2.2

func (l *Log) Println(msg ...any)

func (*Log) SetLevel added in v1.1.0

func (l *Log) SetLevel(level Level)

SetLevel define log level

func (Log) Start added in v1.2.13

func (cron Log) Start()

func (Log) Stop added in v1.2.13

func (cron Log) Stop()

func (*Log) Text added in v1.2.13

func (l *Log) Text()

Text SetJsonFormat define log output format

func (*Log) TextColorDisable added in v1.2.13

func (l *Log) TextColorDisable(timeFormat string)

func (*Log) TextFormatDetail added in v1.2.13

func (l *Log) TextFormatDetail(timeFormat string, disableTime, disableColor, disableLevel bool)

func (*Log) TextTime added in v1.2.13

func (l *Log) TextTime(timeFormat string)

func (*Log) TextTimeDisable added in v1.2.13

func (l *Log) TextTimeDisable()

func (*Log) Values added in v1.2.13

func (l *Log) Values(values ...any) *Log

func (*Log) Warn added in v1.1.0

func (l *Log) Warn(msg string)

func (*Log) WarnValues added in v1.3.14

func (l *Log) WarnValues(values ...any)

func (*Log) Warnf added in v1.2.6

func (l *Log) Warnf(format string, msg ...any)

func (*Log) Warnln added in v1.2.12

func (l *Log) Warnln(msg ...any)

func (*Log) WithField added in v1.2.3

func (l *Log) WithField(key string, value any)

func (*Log) WithFields added in v1.1.0

func (l *Log) WithFields(fields map[string]any)

WithFields appends fields to log

func (*Log) WithKeys added in v1.2.13

func (l *Log) WithKeys(keys ...string)

type Mu added in v1.1.0

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

func NewMutex added in v1.1.0

func NewMutex() *Mu

func (*Mu) Lock added in v1.1.0

func (m *Mu) Lock()

func (*Mu) UnLock added in v1.1.0

func (m *Mu) UnLock()

type ReportFormat added in v1.1.0

type ReportFormat interface {
	Format(*Entry) ([]byte, error)
}

ReportFormat interface

type Task added in v1.2.13

type Task interface{ Run() }

type TaskFunc added in v1.2.13

type TaskFunc func() error

func (TaskFunc) Run added in v1.2.13

func (f TaskFunc) Run()

type TextFormat added in v1.2.2

type TextFormat struct {
	// TimeFormat
	TimeFormat string
	// Disable
	DisableTime  bool
	DisableLevel bool
	DisableColor bool
}

func NewFormatText added in v1.2.13

func NewFormatText() *TextFormat

func (*TextFormat) Format added in v1.2.2

func (t *TextFormat) Format(e *Entry) ([]byte, error)

Jump to

Keyboard shortcuts

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