logger

package module
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: MIT Imports: 20 Imported by: 1

README

logger

base on slog 该库并非同步打印,不会阻塞进程

usage

install

go get -u github.com/ndsky1003/logger
func main(){
        defer logger.Close() //chan 当的锁,为了保证其全部写入
    }


func main() {
        logger.SetLevel(slog.LevelInfo) // 设置打印等级
	logger.Info("nihao")
	logger.Infof("nihao:%s", "ppxia")
	test()
	logger.Fields().Add("age", slog.Int64Value(18)).Info("show age")
	select {}
}

func test() {
	ff := logger.Fields()
	defer ff.Info("ppxia")
	ff.Add("nihao", slog.StringValue("123"))
	ff.Add("nihao1", slog.StringValue("123"))
	ff.Add("nihao2", slog.StringValue("123"))
	ff.Add("nihao3", slog.StringValue("123"))
}
切换handler

默认的是自定义的CustomHandler,handler在使用handle这个函数,只需要实现该函数即可

	logger.SetCreateHandler(func(w io.Writer, opt *slog.HandlerOptions) slog.Handler {
		// return slog.NewJSONHandler(w, opt)
		return slog.NewTextHandler(w, opt)
	})

Documentation

Overview

copy from offical

copy from offical

Index

Constants

View Source
const (
	LevelTrace     = slog.Level(-8)
	LevelDebug     = slog.LevelDebug
	LevelInfo      = slog.LevelInfo
	LevelNotice    = slog.Level(2)
	LevelWarn      = slog.LevelWarn
	LevelErr       = slog.LevelError
	LevelEmergency = slog.Level(12)
	LevelFatal     = slog.Level(16)
)

这里没有位运算

Variables

This section is empty.

Functions

func AppendSlogValue added in v1.0.2

func AppendSlogValue(v slog.Value, dst []byte) []byte

func Close added in v1.0.2

func Close()

func Debug

func Debug(msg ...any)

func Debugf

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

func Default

func Default() *logger

func Emergency

func Emergency(msg ...any)

func Emergencyf

func Emergencyf(msg string, args ...any)

func Err

func Err(msg ...any)

func Errf

func Errf(msg string, args ...any)

func Fatal added in v1.0.8

func Fatal(v ...any)

func Fatalf added in v1.0.8

func Fatalf(format string, v ...any)

func Fields

func Fields() field

func Flush added in v1.0.7

func Flush()

func Info

func Info(msg ...any)

func Infof

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

func IsEmpty added in v1.0.2

func IsEmpty(a slog.Attr) bool

func NewCustomHandler added in v1.0.2

func NewCustomHandler(w io.Writer, opts *slog.HandlerOptions) *custom_handler

func Notice

func Notice(msg ...any)

func Noticef

func Noticef(msg string, args ...any)

func SetCreateHandler added in v1.0.2

func SetCreateHandler(fn create_handler)

func SetFolder added in v1.0.4

func SetFolder(f string)

func SetLevel

func SetLevel(v slog.Level)

api

func Trace

func Trace(msg ...any)

func Tracef

func Tracef(msg string, args ...any)

func Warn

func Warn(msg ...any)

func Warnf

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

Types

type Buffer added in v1.0.2

type Buffer []byte

buffer adapted from go/src/fmt/print.go

func NewBuffer added in v1.0.2

func NewBuffer() *Buffer

func (*Buffer) Free added in v1.0.2

func (b *Buffer) Free()

func (*Buffer) Reset added in v1.0.2

func (b *Buffer) Reset()

func (*Buffer) String added in v1.0.2

func (b *Buffer) String() string

func (*Buffer) Write added in v1.0.2

func (b *Buffer) Write(p []byte) (int, error)

func (*Buffer) WriteByte added in v1.0.2

func (b *Buffer) WriteByte(c byte) error

func (*Buffer) WritePosInt added in v1.0.2

func (b *Buffer) WritePosInt(i int)

func (*Buffer) WritePosIntWidth added in v1.0.2

func (b *Buffer) WritePosIntWidth(i, width int)

WritePosIntWidth writes non-negative integer i to the buffer, padded on the left by zeroes to the given width. Use a width of 0 to omit padding.

func (*Buffer) WriteString added in v1.0.2

func (b *Buffer) WriteString(s string) (int, error)

Jump to

Keyboard shortcuts

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