log

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: MIT Imports: 9 Imported by: 0

README

log

log provides functionality for logging messages at various severity levels.

Functions

debug(msg, *misc, **kv)

Logs a message at the debug log level.

Parameters
name type description
msg string The message to log.
misc *args Additional message arguments will be concatenated to the message string separated by a space.
kv **kwargs Key-value pairs to provide additional debug information.
Examples

basic

Log a debug message with additional information.

load("log", "debug")
debug("Fetching data at", "21:40", retry_attempt=1)
{"retry_attempt": 1}
info(msg, *misc, **kv)

Logs a message at the info log level.

Parameters
name type description
msg string The message to log.
misc *args Additional message arguments will be concatenated to the message string separated by a space.
kv **kwargs Key-value pairs to provide additional information.
Examples

basic

Log an info message with additional information.

load("log", "info")
info("Data fetched", response_time=42)
warn(msg, *misc, **kv)

Logs a message at the warn log level.

Parameters
name type description
msg string The message to log.
misc *args Additional message arguments will be concatenated to the message string separated by a space.
kv **kwargs Key-value pairs to provide additional warning information.
Examples

basic

Log a warning message with additional information.

load("log", "warn")
warn("Fetching data took longer than expected", response_time=123)
error(msg, *misc, **kv)

Logs a message at the error log level and returns an error.

Parameters
name type description
msg string The message to log.
misc *args Additional message arguments will be concatenated to the message string separated by a space.
kv **kwargs Key-value pairs to provide additional error information.
Examples

basic

Log an error message with additional information.

load("log", "error")
error("Failed to fetch data", response_time=240)
fatal(msg, *misc, **kv)

Logs a message at the error log level, returns a fail(msg) to halt program execution.

Parameters
name type description
msg string The message to log.
misc *args Additional message arguments will be concatenated to the message string separated by a space.
kv **kwargs Key-value pairs to provide additional fatal error information.
Examples

basic

Log a fatal error message with additional information.

load("log", "fatal")
fatal("Failed to fetch data and cannot recover", retry_attempts=3, response_time=360)

Documentation

Overview

Package log provides functionality for logging messages at various severity levels in the Starlark environment.

Index

Constants

View Source
const ModuleName = "log"

ModuleName defines the expected name for this Module when used in starlark's load() function, eg: load('log', 'info')

Variables

View Source
var (

	// LoadModule loads the default log module. It is concurrency-safe and idempotent.
	LoadModule = defaultModule.LoadModule
	// SetLog sets the logger of the default log module from outside the package. If l is nil, a noop logger is used, which does nothing.
	SetLog = defaultModule.SetLog
)

Initialized as global functions to be used as default

Functions

func NewDefaultLogger

func NewDefaultLogger() *zap.SugaredLogger

NewDefaultLogger creates a new logger as a default. It is used when no logger is provided to NewModule.

Types

type Module

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

Module wraps the starlark module for the log package.

func NewModule

func NewModule(lg *zap.SugaredLogger) *Module

NewModule creates a new log module. If logger is nil, a new development logger is created.

func (*Module) LoadModule

func (m *Module) LoadModule() (starlark.StringDict, error)

LoadModule returns the log module loader. It is concurrency-safe and idempotent.

func (*Module) SetLog

func (m *Module) SetLog(l *zap.SugaredLogger)

SetLog sets the logger of the log module from outside the package. If l is nil, a noop logger is used, which does nothing.

Jump to

Keyboard shortcuts

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