logging

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: GPL-3.0 Imports: 9 Imported by: 5

Documentation

Overview

Package logging provides tools for easy logging errors with traceback. Logging package is written over slog.Logger.

Index

Constants

This section is empty.

Variables

View Source
var Levels = struct {
	INFO, DEBUG, WARN, ERROR slog.Level
}{
	INFO:  slog.LevelInfo,
	DEBUG: slog.LevelDebug,
	WARN:  slog.LevelWarn,
	ERROR: slog.LevelError,
}

Levels are a simple abstractions on slog.Level.

Functions

func GetInstance

func GetInstance(logLevel slog.Level, logFilePath string) *slog.Logger

GetInstance implemented as singleton pattern to get Logger instance, created once for whole app:.

func GetLogTraceback

func GetLogTraceback(skipLevel int) string

GetLogTraceback return a string with info about filename, function name and line https://stackoverflow.com/questions/25927660/how-to-get-the-current-function-name

func LogError added in v1.0.5

func LogError(logger *slog.Logger, msg string, err error)

LogError logs error with message info, using provided logger.

func LogErrorContext added in v1.0.5

func LogErrorContext(ctx context.Context, logger *slog.Logger, msg string, err error)

LogErrorContext uses provided logger to save error with message info and context. Context is used to get request ID and connect it with error.

func LogInfo added in v1.0.9

func LogInfo(logger *slog.Logger, msg string)

LogInfo logs message, using provided logger.

func LogRequest added in v1.0.5

func LogRequest(ctx context.Context, logger *slog.Logger, request any)

LogRequest uses provided logger to save request info and connect it with request ID from the context.

Types

type Config

type Config struct {
	Level       slog.Level
	LogFilePath string
}

Config is a logging config, on base of which logger instance is created.

Jump to

Keyboard shortcuts

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