log

package
v0.0.0-...-e4df553 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogFileName        = "certsuite.log"
	LogFilePermissions = 0o644
)
View Source
const (
	LevelDebug = "debug"
	LevelInfo  = "info"
	LevelWarn  = "warn"
	LevelError = "error"
	LevelFatal = "fatal"
)

Log levels

View Source
const CustomLevelFatal = slog.Level(12)

Custom log levels

Variables

View Source
var CustomLevelNames = map[slog.Leveler]string{
	CustomLevelFatal: "FATAL",
}

Functions

func CloseGlobalLogFile

func CloseGlobalLogFile() error

func CreateGlobalLogFile

func CreateGlobalLogFile(outputDir, logLevel string) error

func Debug

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

Top-level log functions

func Error

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

func Fatal

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

func Info

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

func Logf

func Logf(logger *Logger, level, format string, args ...any)

The Logf function should be called inside a log wrapper function. Otherwise the code source reference will be invalid.

func SetLogger

func SetLogger(l *Logger)

func SetupLogger

func SetupLogger(logWriter io.Writer, level string)

func Warn

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

Types

type CustomHandler

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

func NewCustomHandler

func NewCustomHandler(out io.Writer, opts *slog.HandlerOptions) *CustomHandler

func (*CustomHandler) Enabled

func (h *CustomHandler) Enabled(_ context.Context, level slog.Level) bool

func (*CustomHandler) Handle

func (h *CustomHandler) Handle(_ context.Context, r slog.Record) error

The Handle method will write a log line with the following format: LOG_LEVEL [TIME] [SOURCE_FILE] [CUSTOM_ATTRS] MSG

func (*CustomHandler) WithAttrs

func (h *CustomHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*CustomHandler) WithGroup

func (h *CustomHandler) WithGroup(_ string) slog.Handler

Not implemented. Returns the nil handler.

type Logger

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

func GetLogger

func GetLogger() *Logger

func GetMultiLogger

func GetMultiLogger(writers ...io.Writer) *Logger

func (*Logger) Debug

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

Log methods for a logger instance

func (*Logger) Error

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

func (*Logger) Fatal

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

func (*Logger) Info

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

func (*Logger) Warn

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

func (*Logger) With

func (logger *Logger) With(args ...any) *Logger

type MultiHandler

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

func NewMultiHandler

func NewMultiHandler(handlers ...slog.Handler) *MultiHandler

func (*MultiHandler) Enabled

func (h *MultiHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*MultiHandler) Handle

func (h *MultiHandler) Handle(ctx context.Context, r slog.Record) error

func (*MultiHandler) WithAttrs

func (h *MultiHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*MultiHandler) WithGroup

func (h *MultiHandler) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

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