wlog

package module
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 11 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.
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
l := New()
f := make(Fields)
f["field1"] = "value1"
f["field2"] = "value2"
l.WithFields(f)
l.Info("test message")
  1. Custom output format (default text format)
l := New()
l.SetJsonFormat()
l.Info("test message")
  1. Custom output
l := New()
f, _ := os.Create("test.json")
defer f.Close()
l.SetOutput(f)
l.Info("test message")

  1. Caller
l := New()
l.ReportCaller()
f := make(Fields)
f["key"] = "value"
defer f.Close()
l.SetOutput(f)
l.Info("test message")
``
7. Output 
```stdout
level="error"	 time="2024-03-01 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-03-01 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/2/21 18:29: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

This section is empty.

Functions

func Debug

func Debug(msg string)

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 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 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 Infof added in v1.2.11

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

func Infoln added in v1.2.12

func Infoln(msg ...any)

func NewEntryPool added in v1.1.0

func NewEntryPool(l *Log)

func Panic added in v1.2.2

func Panic(msg string)

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 Print added in v1.2.2

func Print()

func Printf added in v1.2.2

func Printf()

func Println added in v1.2.2

func Println()

func ReportCal added in v1.2.12

func ReportCal()

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)

Types

type BufferPool added in v1.1.0

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

BufferPool interface

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) 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 JsonFormat added in v1.1.0

type JsonFormat struct {
	TimeFormat string // time format

	DisableTime  bool
	DisableLevel bool
	DisableColor bool
}

func DefaultJsonFormat added in v1.2.2

func DefaultJsonFormat() *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
	// contains filtered or unexported fields
}

func New added in v1.1.0

func New() *Log

New create default logger

func (*Log) Debug added in v1.1.0

func (l *Log) Debug(msg string)

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) 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) 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) Info added in v1.1.0

func (l *Log) Info(msg string)

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) Panic added in v1.2.2

func (l *Log) Panic(msg string)

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()

func (*Log) Printf added in v1.2.2

func (l *Log) Printf()

func (*Log) Println added in v1.2.2

func (l *Log) Println()

func (*Log) ReportCaller added in v1.2.8

func (l *Log) ReportCaller()

func (*Log) SetFormatter added in v1.2.4

func (l *Log) SetFormatter(f ReportFormat)

SetFormatter custom log formatter

func (*Log) SetJsonColorDisable added in v1.2.12

func (l *Log) SetJsonColorDisable(timeFormat string)

func (*Log) SetJsonFormat added in v1.2.2

func (l *Log) SetJsonFormat()

SetJsonFormat define log output format

func (*Log) SetJsonFormatDetail added in v1.2.12

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

func (*Log) SetJsonTime added in v1.2.12

func (l *Log) SetJsonTime(timeFormat string)

func (*Log) SetJsonTimeDisable added in v1.2.12

func (l *Log) SetJsonTimeDisable()

func (*Log) SetLevel added in v1.1.0

func (l *Log) SetLevel(level Level)

SetLevel define log level

func (*Log) SetOutput added in v1.2.2

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

SetOutput define log output

func (*Log) SetTextColorDisable added in v1.2.12

func (l *Log) SetTextColorDisable(timeFormat string)

func (*Log) SetTextFormatDetail added in v1.2.12

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

func (*Log) SetTextTime added in v1.2.12

func (l *Log) SetTextTime(timeFormat string)

func (*Log) SetTextTimeDisable added in v1.2.12

func (l *Log) SetTextTimeDisable()

func (*Log) Warn added in v1.1.0

func (l *Log) Warn(msg string)

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 Fields)

WithFields appends fields to log

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 TextFormat added in v1.2.2

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

func DefaultTextFormat added in v1.2.2

func DefaultTextFormat() *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