log

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelTrace   = slog.Level(-8)
	LevelDebug   = slog.LevelDebug
	LevelInfo    = slog.LevelInfo
	LevelWarning = slog.LevelWarn
	LevelError   = slog.LevelError
	LevelStack   = slog.Level(12)
	LevelDump    = slog.Level(16)
	LevelFatal   = slog.Level(20)
)

levels

Variables

View Source
var LogChannelCap int
View Source
var LogLevel slog.Level = LevelTrace
View Source
var LogPath string
View Source
var LogSize int64
View Source
var OpenConsole bool

Functions

func Any

func Any(key string, value any) slog.Attr

func Bool

func Bool(key string, v bool) slog.Attr

func Close

func Close()

func Debug

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

func Dump

func Dump(dump string, args ...any)

func Duration

func Duration(key string, v time.Duration) slog.Attr

func Error

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

func ErrorAttr

func ErrorAttr(key string, value error) slog.Attr

func Fatal

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

func Float64

func Float64(key string, v float64) slog.Attr

func Group

func Group(key string, args ...any) slog.Attr

func Info

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

func Int

func Int(key string, value int) slog.Attr

func Int16

func Int16(key string, value int16) slog.Attr

func Int32

func Int32(key string, value int32) slog.Attr

func Int64

func Int64(key string, value int64) slog.Attr

func Int8

func Int8(key string, value int8) slog.Attr

func NewOriginJsonHandler

func NewOriginJsonHandler(level slog.Level, w io.Writer, addSource bool, replaceAttr func([]string, slog.Attr) slog.Attr) slog.Handler

func NewOriginTextHandler

func NewOriginTextHandler(level slog.Level, w io.Writer, addSource bool, replaceAttr func([]string, slog.Attr) slog.Attr) slog.Handler

func SDebug

func SDebug(a ...interface{})

func SError

func SError(a ...interface{})

func SInfo

func SInfo(a ...interface{})

func STrace

func STrace(a ...interface{})

func SWarning

func SWarning(a ...interface{})

func SetLogger added in v2.0.2

func SetLogger(logger ILogger)

It's non-thread-safe

func Stack

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

func String

func String(key, value string) slog.Attr

func Time

func Time(key string, v time.Time) slog.Attr

func Trace

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

func Uint

func Uint(key string, value uint) slog.Attr

func Uint16

func Uint16(key string, value uint16) slog.Attr

func Uint32

func Uint32(key string, value uint32) slog.Attr

func Uint64

func Uint64(key string, v uint64) slog.Attr

func Uint8

func Uint8(key string, value uint8) slog.Attr

func Warning

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

Types

type BaseHandler

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

func (*BaseHandler) Fill

func (b *BaseHandler) Fill(context context.Context, record *slog.Record)

func (*BaseHandler) Lock

func (b *BaseHandler) Lock()

func (*BaseHandler) UnLock

func (b *BaseHandler) UnLock()

type Buffer

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

func (*Buffer) AppendBool

func (b *Buffer) AppendBool(v bool)

AppendBool appends a bool to the underlying buffer.

func (*Buffer) AppendByte

func (b *Buffer) AppendByte(v byte)

AppendByte writes a single byte to the Buffer.

func (*Buffer) AppendBytes

func (b *Buffer) AppendBytes(v []byte)

func (*Buffer) AppendFloat

func (b *Buffer) AppendFloat(f float64, bitSize int)

AppendFloat appends a float to the underlying buffer. It doesn't quote NaN or +/- Inf.

func (*Buffer) AppendInt

func (b *Buffer) AppendInt(i int64)

AppendInt appends an integer to the underlying buffer (assuming base 10).

func (*Buffer) AppendString

func (b *Buffer) AppendString(s string)

AppendString writes a string to the Buffer.

func (*Buffer) AppendUint

func (b *Buffer) AppendUint(i uint64)

AppendUint appends an unsigned integer to the underlying buffer (assuming base 10).

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns a mutable reference to the underlying byte slice.

func (*Buffer) Cap

func (b *Buffer) Cap() int

Cap returns the capacity of the underlying byte slice.

func (*Buffer) Init

func (buff *Buffer) Init()

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the length of the underlying byte slice.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset resets the underlying byte slice. Subsequent writes re-use the slice's backing array.

func (*Buffer) String

func (b *Buffer) String() string

String returns a string copy of the underlying byte slice.

func (*Buffer) TrimNewline

func (b *Buffer) TrimNewline()

TrimNewline trims any final "\n" byte from the end of the buffer.

func (*Buffer) Write

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

Write implements io.Writer.

type ILogger added in v2.0.2

type ILogger interface {
	Trace(msg string, args ...any)
	Debug(msg string, args ...any)
	Info(msg string, args ...any)
	Warning(msg string, args ...any)
	Error(msg string, args ...any)
	Stack(msg string, args ...any)
	Dump(msg string, args ...any)
	Fatal(msg string, args ...any)

	DoSPrintf(level slog.Level, a []interface{})
	FormatHeader(buf *Buffer, level slog.Level, calldepth int)
	Close()
}

func GetLogger added in v2.0.2

func GetLogger() ILogger

func NewJsonLogger

func NewJsonLogger(level slog.Level, pathName string, filePrefix string, addSource bool, logChannelCap int) (ILogger, error)

func NewTextLogger

func NewTextLogger(level slog.Level, pathName string, filePrefix string, addSource bool, logChannelCap int) (ILogger, error)

type IOriginHandler

type IOriginHandler interface {
	slog.Handler
	Lock()
	UnLock()
}

type IoWriter

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

func (*IoWriter) Close

func (iw *IoWriter) Close() error

func (*IoWriter) Write

func (iw *IoWriter) Write(p []byte) (n int, err error)

type Logger

type Logger struct {
	Slogger *slog.Logger
	// contains filtered or unexported fields
}

func (*Logger) Close

func (logger *Logger) Close()

It's dangerous to call the method on logging

func (*Logger) Debug

func (logger *Logger) Debug(msg string, args ...any)

func (*Logger) DoSPrintf added in v2.0.2

func (logger *Logger) DoSPrintf(level slog.Level, a []interface{})

func (*Logger) Dump

func (logger *Logger) Dump(msg string, args ...any)

func (*Logger) Error

func (logger *Logger) Error(msg string, args ...any)

func (*Logger) Fatal

func (logger *Logger) Fatal(msg string, args ...any)

func (*Logger) FormatHeader added in v2.0.2

func (logger *Logger) FormatHeader(buf *Buffer, level slog.Level, calldepth int)

func (*Logger) Info

func (logger *Logger) Info(msg string, args ...any)

func (*Logger) SDebug

func (logger *Logger) SDebug(a ...interface{})

func (*Logger) SError

func (logger *Logger) SError(a ...interface{})

func (*Logger) SInfo

func (logger *Logger) SInfo(a ...interface{})

func (*Logger) STrace

func (logger *Logger) STrace(a ...interface{})

func (*Logger) SWarning

func (logger *Logger) SWarning(a ...interface{})

func (*Logger) Stack

func (logger *Logger) Stack(msg string, args ...any)

func (*Logger) Trace

func (logger *Logger) Trace(msg string, args ...any)

func (*Logger) Warning

func (logger *Logger) Warning(msg string, args ...any)

type OriginJsonHandler

type OriginJsonHandler struct {
	BaseHandler
	*slog.JSONHandler
}

func (*OriginJsonHandler) Handle

func (oh *OriginJsonHandler) Handle(context context.Context, record slog.Record) error

type OriginTextHandler

type OriginTextHandler struct {
	BaseHandler
	*slog.TextHandler
}

func (*OriginTextHandler) Handle

func (oh *OriginTextHandler) Handle(context context.Context, record slog.Record) error

Jump to

Keyboard shortcuts

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