cblog

package module
v0.5.11 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 5 Imported by: 2

README

Channel Based back-end for slog.Logger

Go Reference

See also

Documentation

Overview

Package cblog provides a channel based logger

Index

Constants

View Source
const (
	// DefaultOutputBufferSize is the default size of the channel buffer used for logging.
	DefaultOutputBufferSize = 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LogMsg

type LogMsg struct {
	Message string
	Level   slog.LogLevel
	Fields  map[string]any
	Stack   core.Stack
}

LogMsg represents one structured log entry

type Logger

type Logger struct {
	internal.Loglet
	// contains filtered or unexported fields
}

Logger is a slog.Logger using a channel as backend

func New

func New(ch chan LogMsg) (*Logger, <-chan LogMsg)

New creates a new Channel Based Logger

func NewWithCallback

func NewWithCallback(size int, h func(LogMsg)) *Logger

NewWithCallback creates a logger and attached a goroutine to call a provided handler, sequentially, for each log entry

func (*Logger) Debug

func (l *Logger) Debug() slog.Logger

Debug returns a new logger set to add entries as level Debug

func (*Logger) Enabled

func (*Logger) Enabled() bool

Enabled tells this logger is enabled

func (*Logger) Error

func (l *Logger) Error() slog.Logger

Error returns a new logger set to add entries as level Error

func (*Logger) Fatal

func (l *Logger) Fatal() slog.Logger

Fatal returns a new logger set to add entries as level Fatal

func (*Logger) Info

func (l *Logger) Info() slog.Logger

Info returns a new logger set to add entries as level Info

func (*Logger) Panic

func (l *Logger) Panic() slog.Logger

Panic returns a new logger set to add entries as level Panic

func (*Logger) Print

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

Print adds a log entry with arguments handled in the manner of fmt.Print

func (*Logger) Printf

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

Printf adds a log entry with arguments handled in the manner of fmt.Printf

func (*Logger) Println

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

Println adds a log entry with arguments handled in the manner of fmt.Println

func (*Logger) Warn

func (l *Logger) Warn() slog.Logger

Warn returns a new logger set to add entries as level Warn

func (*Logger) WithEnabled

func (l *Logger) WithEnabled() (slog.Logger, bool)

WithEnabled passes the logger and if it's enabled

func (*Logger) WithField

func (l *Logger) WithField(label string, value any) slog.Logger

WithField returns a new logger with a field attached

func (*Logger) WithFields

func (l *Logger) WithFields(fields map[string]any) slog.Logger

WithFields returns a new logger with a set of fields attached

func (*Logger) WithLevel

func (l *Logger) WithLevel(level slog.LogLevel) slog.Logger

WithLevel returns a new logger set to add entries to the specified level

func (*Logger) WithStack

func (l *Logger) WithStack(skip int) slog.Logger

WithStack attaches a call stack to a new logger

Jump to

Keyboard shortcuts

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