log

package
v0.0.0-...-e55081e Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KindAny       = slog.KindAny
	KindBool      = slog.KindBool
	KindDuration  = slog.KindDuration
	KindFloat64   = slog.KindFloat64
	KindInt64     = slog.KindInt64
	KindString    = slog.KindString
	KindTime      = slog.KindTime
	KindUint64    = slog.KindUint64
	KindGroup     = slog.KindGroup
	KindLogValuer = slog.KindLogValuer
)

Variables

View Source
var (
	MessageKey = "msg"
	LevelKey   = "level"
	ErrKey     = "err"
	NameKey    = "logger"

	// ErrorHandler is called whenever fails to write an event on its
	// output. default an error is printed on the stderr. This handler must
	// be thread safe and non-blocking.
	ErrorHandler func(err error) = func(err error) {
		_, _ = fmt.Fprintf(os.Stderr, "log: write failed, %v\n", err)
	}

	// Sprint is used to concatenate log message components into a single string.
	// It formats its arguments using the default behavior (fmt.Sprint).
	// The caller can replace this function to customize the log message formatting.
	Sprint func(a ...any) string = fmt.Sprint
	// Sprintf is used to format log messages with a specific format string.
	// It formats its arguments using the default behavior (fmt.Sprintf).
	// The caller can replace this function to customize the format or behavior of the log messages.
	Sprintf func(format string, a ...any) string = fmt.Sprintf
)
View Source
var (
	// DefaultCaller is a Valuer that returns the file and line.
	DefaultCaller = Caller(6)

	// DefaultTimestamp is a Valuer that returns the current wallclock time.
	DefaultTimestamp = Timestamp(time.RFC3339)
)
View Source
var File_log_log_proto protoreflect.FileDescriptor
View Source
var (
	Group = slog.Group
)

Functions

func AddFlags

func AddFlags(fs *flag.FlagSet)

func Close

func Close() error

func Debug

func Debug(args ...any)

Debug logs a message at debug level.

func DebugS

func DebugS(msg string, kvs ...any)

DebugS logs a message at debug level with key vals.

func Debugf

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

Debugf logs a message at debug level.

func Error

func Error(args ...any)

Error logs a message at error level.

func ErrorS

func ErrorS(err error, msg string, kvs ...any)

ErrorS logs a message at error level with key vals.

func Errorf

func Errorf(format string, args ...any)

Errorf logs a message at error level.

func Fatal

func Fatal(args ...any)

Fatal logs a message at fatal level.

func FatalS

func FatalS(msg string, kvs ...any)

FatalS logs a message at fatal level with key vals.

func Fatalf

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

Fatalf logs a message at fatal level.

func Info

func Info(args ...any)

Info logs a message at info level.

func InfoS

func InfoS(msg string, kvs ...any)

InfoS logs a message at info level with key vals.

func Infof

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

Infof logs a message at info level.

func InitManager

func InitManager(name string, kvs ...any)

InitManager init global manager

func SetHandler

func SetHandler(h Handler)

func SetLevel

func SetLevel(l Level)

func SetLogger

func SetLogger(l *Logger)

func SetOutput

func SetOutput(w io.Writer)

func Warn

func Warn(args ...any)

Warn logs a message at warn level.

func WarnS

func WarnS(msg string, kvs ...any)

WarnS logs a message at warn level with key vals.

func Warnf

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

Warnf logs a message at warn level.

func Writer

func Writer() io.Writer

Types

type Handler

type Handler interface {
	With(kvs ...any) Handler
	Log(ctx context.Context, w io.Writer, level Level, msg string, kvs ...any) error
}

func Json

func Json() Handler

func JsonWithName

func JsonWithName(name string) Handler

func Text

func Text() Handler

func TextWithName

func TextWithName(name string) Handler

type JsonHandler

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

func (*JsonHandler) Log

func (j *JsonHandler) Log(ctx context.Context, w io.Writer, level Level, msg string, kvs ...any) error

func (*JsonHandler) With

func (j *JsonHandler) With(kvs ...any) Handler

type Kind

type Kind = slog.Kind

type Level

type Level int8

Level is a logger level.

const (
	LevelDebug Level = -4
	LevelInfo  Level = 0
	LevelWarn  Level = 4
	LevelError Level = 8
	LevelFatal Level = 12
)

func ParseLevel

func ParseLevel(s string) Level

func (Level) String

func (l Level) String() string

type Logger

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

func GetLogger

func GetLogger() *Logger

func L

func L(name ...string) *Logger

func New

func New(w io.Writer, h ...Handler) *Logger

func (*Logger) Close

func (l *Logger) Close() error

func (*Logger) Debug

func (l *Logger) Debug(args ...any)

Debug logs a message at debug level.

func (*Logger) DebugS

func (l *Logger) DebugS(msg string, kvs ...any)

DebugS logs a message at debug level with kvs.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...any)

Debugf logs a message at debug level.

func (*Logger) Error

func (l *Logger) Error(args ...any)

Error logs a message at error level.

func (*Logger) ErrorS

func (l *Logger) ErrorS(err error, msg string, kvs ...any)

ErrorS logs a message at error level with kvs.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...any)

Errorf logs a message at warn level.

func (*Logger) Fatal

func (l *Logger) Fatal(args ...any)

Fatal logs a message at fatal level.

func (*Logger) FatalS

func (l *Logger) FatalS(msg string, kvs ...any)

FatalS logs a message at fatal level with kvs.

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...any)

Fatalf logs a message at warn level.

func (*Logger) Info

func (l *Logger) Info(args ...any)

Info logs a message at info level.

func (*Logger) InfoS

func (l *Logger) InfoS(msg string, kvs ...any)

InfoS logs a message at info level with kvs.

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...any)

Infof logs a message at info level.

func (*Logger) Log

func (l *Logger) Log(level klog.Level, kvs ...any) error

func (*Logger) SetHandler

func (l *Logger) SetHandler(h Handler)

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

func (*Logger) SetOutput

func (l *Logger) SetOutput(w io.Writer)

func (*Logger) Warn

func (l *Logger) Warn(args ...any)

Warn logs a message at warn level.

func (*Logger) WarnS

func (l *Logger) WarnS(msg string, kvs ...any)

WarnS logs a message at warn level with kvs.

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...any)

Warnf logs a message at warn level.

func (*Logger) With

func (l *Logger) With(kvs ...any) *Logger

func (*Logger) WithContext

func (l *Logger) WithContext(ctx context.Context) *Logger

func (*Logger) Writer

func (l *Logger) Writer() io.Writer

type Manager

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

func M

func M() *Manager

func NewManager

func NewManager(name string, kvs ...any) *Manager

func (*Manager) Add

func (m *Manager) Add(name string, kvs ...any) (*Logger, error)

func (*Manager) AddWithSuffix

func (m *Manager) AddWithSuffix(suffix string, kvs ...any) (*Logger, error)

func (*Manager) Apply

func (m *Manager) Apply(opts *Options) *Options

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) Get

func (m *Manager) Get(name ...string) *Logger

type Options

type Options struct {
	Format     string `protobuf:"bytes,1,opt,name=format,proto3" json:"format,omitempty"`
	Level      string `protobuf:"bytes,2,opt,name=level,proto3" json:"level,omitempty"`
	Output     string `protobuf:"bytes,3,opt,name=output,proto3" json:"output,omitempty"`
	Dir        string `protobuf:"bytes,4,opt,name=dir,proto3" json:"dir,omitempty"`
	MaxSize    int64  `protobuf:"varint,5,opt,name=maxSize,proto3" json:"maxSize,omitempty"` //MB
	MaxBackups int64  `protobuf:"varint,6,opt,name=maxBackups,proto3" json:"maxBackups,omitempty"`
	// contains filtered or unexported fields
}

func (*Options) Copy

func (o *Options) Copy() *Options

func (*Options) Descriptor deprecated

func (*Options) Descriptor() ([]byte, []int)

Deprecated: Use Options.ProtoReflect.Descriptor instead.

func (*Options) GetDir

func (x *Options) GetDir() string

func (*Options) GetFormat

func (x *Options) GetFormat() string

func (*Options) GetLevel

func (x *Options) GetLevel() string

func (*Options) GetMaxBackups

func (x *Options) GetMaxBackups() int64

func (*Options) GetMaxSize

func (x *Options) GetMaxSize() int64

func (*Options) GetOutput

func (x *Options) GetOutput() string

func (*Options) ProtoMessage

func (*Options) ProtoMessage()

func (*Options) ProtoReflect

func (x *Options) ProtoReflect() protoreflect.Message

func (*Options) Reset

func (x *Options) Reset()

func (*Options) String

func (x *Options) String() string

type TextHandler

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

func (*TextHandler) Log

func (h *TextHandler) Log(ctx context.Context, w io.Writer, level Level, msg string, kvs ...any) error

func (*TextHandler) With

func (h *TextHandler) With(kvs ...any) Handler

type Value

type Value = slog.Value

func ValuerValue

func ValuerValue(ctx context.Context, v Valuer) Value

ValuerValue return the function value.

type Valuer

type Valuer func(ctx context.Context) Value

func Caller

func Caller(depth int) Valuer

func Timestamp

func Timestamp(layout string) Valuer

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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