package log

import "hauru.club/x/okrzeja/service/log"

Package log implements logging and telemetry utilities for okrzeja web server.

You configure logging in Okrzeja by setting up environmental variable OKRZEJA_ENV.

Available values for OKRZEJA_ENV are:

Index

Functions

func ContextWithFields

func ContextWithFields(ctx context.Context, fields ...slog.Attr) context.Context

ContextWithFields fills context with logging key/value fields that will be used by every logging event that accepts context as argument.

If there are already some fields in the context, new fields will be appended.

func Error

func Error(ctx context.Context, msg string, err error)

Error logs message about given error at the ERROR level.

func ErrorInfo

func ErrorInfo(ctx context.Context, msg string, err error)

ErrorInfo logs message about given error at the INFO level.

func FirstAdminUser

func FirstAdminUser(ctx context.Context, id uuid.UUID, username string)

FirstAdminUser is event fired when first user has been registered and marked as admin user as well.

func HTTPKnownError

func HTTPKnownError(ctx context.Context, err error)

HTTPKnownError logs information about non-critical error from HTTP server that is well defined and expected.

For example: requested resource was not found or user doesn't have access to requested resources.

func NewLogFormatter

func NewLogFormatter() middleware.LogFormatter

NewLogFormatter returns chi LogFormatter interface implementation for okrzeja internal logger.

func ServerShutdown

func ServerShutdown()

ServerShutdown is event fired when HTTP server stops.

func ServerStart

func ServerStart(addr string)

ServerStart is event fired when HTTP server starts.

Types

type Logger

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

Logger logs information about state of the server in the formatted way. The only safe way to initialize Logger is to use NewLogger.

It uses global logger instance of the application.

func NewLogger

func NewLogger(src ...string) *Logger

NewLogger is the only safe constructor for Logger.

You can pass optional source argument which is the source of the log messages.

func (*Logger) Fatal

func (l *Logger) Fatal(v ...interface{})

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, v ...interface{})

func (*Logger) Print

func (l *Logger) Print(v ...interface{})

func (*Logger) Printf

func (l *Logger) Printf(format string, v ...interface{})

func (*Logger) Println

func (l *Logger) Println(v ...interface{})

Source Files

events.go log.go logger.go

Version
v0.0.0-20231010043146-4292577f982b (latest)
Published
Oct 10, 2023
Platform
linux/amd64
Imports
12 packages
Last checked
1 day ago

Tools for package owners.