logger

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelTrace = slog.Level(-8)
	LevelFatal = slog.Level(12)
	LevelPanic = slog.Level(13)
)

Variables

View Source
var LevelNames = map[slog.Leveler]string{
	LevelTrace: "TRACE",
	LevelFatal: "FATAL",
	LevelPanic: "PANIC",
}

Functions

This section is empty.

Types

type Logger

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

Logger manages logging operations with various log levels and modes.

func New

func New(calldepth int, pc []uintptr) *Logger

New creates and initializes a new Logger instance. calldepth: Number of stack frames to ascend for log entries. pc: A slice of uintptr used to store stack trace information.

func (*Logger) Debug

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

Debug logs a debug-level message with optional arguments. msg: The message to log. args: Additional arguments to format the message.

func (*Logger) DebugContext

func (l *Logger) DebugContext(ctx context.Context, msg string, args ...interface{})

DebugContext logs a debug-level message with optional arguments and context. ctx: The context for the log entry. msg: The message to log. args: Additional arguments to format the message.

func (*Logger) Error

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

Error logs an error-level message with optional arguments. msg: The message to log. args: Additional arguments to format the message.

func (*Logger) ErrorContext

func (l *Logger) ErrorContext(ctx context.Context, msg string, args ...any)

ErrorContext logs an error-level message with optional arguments and context. ctx: The context for the log entry. msg: The message to log. args: Additional arguments to format the message.

func (*Logger) Fatal

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

Fatal logs a fatal-level message, then exits the application. msg: The message to log. args: Additional arguments to format the message.

func (*Logger) FatalContext

func (l *Logger) FatalContext(ctx context.Context, msg string, args ...any)

FatalC logs a fatal-level message with context, then exits the application. ctx: The context for the log entry. msg: The message to log. args: Additional arguments to format the message.

func (*Logger) Info

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

Info logs an info-level message with optional arguments. msg: The message to log. args: Additional arguments to format the message.

func (*Logger) InfoContext

func (l *Logger) InfoContext(ctx context.Context, msg string, args ...any)

InfoC logs an info-level message with context and optional arguments. ctx: The context for the log entry. msg: The message to log. args: Additional arguments to format the message.

func (*Logger) Panic

func (l *Logger) Panic(msg string, args ...any)

Panic logs a panic-level message, then panics with the message. msg: The message to log. args: Additional arguments to format the message.

func (*Logger) PanicContext

func (l *Logger) PanicContext(ctx context.Context, msg string, args ...any)

PanicC logs a panic-level message with context, then panics with the context. ctx: The context for the log entry. msg: The message to log. args: Additional arguments to format the message.

func (*Logger) Print

func (l *Logger) Print(msg string, args ...any)

Print logs a trace-level message with optional arguments. msg: The message to log. args: Additional arguments to format the message.

func (*Logger) PrintContext

func (l *Logger) PrintContext(ctx context.Context, msg string, args ...any)

PrintC logs a trace-level message with context and optional arguments. ctx: The context for the log entry. msg: The message to log. args: Additional arguments to format the message.

func (*Logger) SetCalldepth

func (l *Logger) SetCalldepth(calldepth int)

SetCalldepth configures the number of stack frames to ascend for logging. calldepth: The number of stack frames to ascend.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level slog.Level) (oldLevel slog.Level)

SetLevel sets the logging level for the Logger instance. This method updates the log level to the specified level and returns the previous log level.

Parameters:

level (slog.Level) - The new log level to be set. This determines the severity of the logs
                     that will be captured. Common log levels include DEBUG, INFO, WARN, and ERROR.

Returns:

oldLevel (slog.Level) - The previous log level before it was updated. This can be used to restore
                        the previous log level if needed.

Example usage:

logger := &Logger{}
oldLevel := logger.SetLevel(slog.INFO)
// The log level is now set to INFO
// You can restore the old level if needed
logger.SetLevel(oldLevel)

func (*Logger) StackTrace

func (l *Logger) StackTrace() slog.Attr

StackTrace provides a stack trace of up to 10 layers from where the error or incident was generated.

func (*Logger) Warn

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

Warn logs a warning-level message with optional arguments. msg: The message to log. args: Additional arguments to format the message.

func (*Logger) WarnContext

func (l *Logger) WarnContext(ctx context.Context, msg string, args ...any)

WarnContext logs a warning-level message with optional arguments and context. ctx: The context for the log entry. msg: The message to log. args: Additional arguments to format the message.

type Priority

type Priority int8

Priority represents the level of importance for log messages. Higher values indicate greater importance.

Jump to

Keyboard shortcuts

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