logs

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

logs

GitHub release (latest SemVer) GitHub Workflow Status GitHub GitHub go.mod Go version

A Go library that provides a simple interface and functions for logging.

Requirements

  • Go 1.22+

Installation

go get github.com/Siroshun09/logs

License

This project is under the Apache License version 2.0. Please see LICENSE for more info.

Copyright © 2024, Siroshun09

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, msg string)

Debug logs a message as debug level using Logger obtained from FromContext.

func Error

func Error(ctx context.Context, err error)

Error logs an error as error level using Logger obtained from FromContext.

func Info

func Info(ctx context.Context, msg string)

Info logs a message as info level using Logger obtained from FromContext.

func SetDefault

func SetDefault(logger Logger)

SetDefault makes Default return the specified Logger.

If the given Logger is nil, this function triggers a panic.

func Warn

func Warn(ctx context.Context, err error)

Warn logs an error as warn level using Logger obtained from FromContext.

func WithContext

func WithContext(ctx context.Context, logger Logger) context.Context

WithContext puts the Logger into context.Context.

Types

type Logger

type Logger interface {
	// Debug logs a message as debug level.
	Debug(ctx context.Context, msg string)
	// Info logs a message as info level.
	Info(ctx context.Context, msg string)
	// Warn logs an error as warn level.
	Warn(ctx context.Context, err error)
	// Error logs an error as error level.
	Error(ctx context.Context, err error)
}

Logger includes functions to log messages or errors.

func Default

func Default() Logger

Default returns a Logger set by SetDefault, or default Logger instance that uses slog.Default.

func FromContext

func FromContext(ctx context.Context) Logger

FromContext takes the Logger from context.Context.

If the given context.Context does not have the Logger, this function returns Default.

func NewLoggerWithSlog

func NewLoggerWithSlog(logger *slog.Logger) Logger

NewLoggerWithSlog creates Logger using slog.Logger.

Jump to

Keyboard shortcuts

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