alog

package
v0.0.0-...-7d4a354 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package alog implements leveled execution logs for Agricola.

The package implements an interface similar to the standard Go log that is inspired by Google's glog package.

The logging in Agricola is implemented as its own package to later extract it as a separate package to use across different Go project.

Index

Constants

View Source
const ExitLogError = 5

ExitLogError is the exit code when the program exits for error in logging.

Variables

This section is empty.

Functions

func Error

func Error(args ...any)

Error logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func ErrorDepth

func ErrorDepth(depth int, args ...any)

ErrorDepth acts as Error but uses depth to determine which call frame to log. ErrorDepth(0, "msg") is the same as Error("msg").

func ErrorDepthf

func ErrorDepthf(depth int, format string, args ...any)

ErrorDepthf acts as Errorf but uses depth to determine which call frame to log. ErrorDepthf(0, "msg") is the same as Errorf("msg").

func Errorf

func Errorf(format string, args ...any)

Errorf logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func Errorln

func Errorln(args ...any)

Errorln logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Println; a newline is appended if missing.

func Info

func Info(args ...any)

Info logs to the INFO log. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func InfoDepth

func InfoDepth(depth int, args ...any)

InfoDepth calls Info from a different depth in the call stack. This enables a callee to emit logs that use the callsite information of its caller or any other callers in the stack. When depth == 0, the original callee's line information is emitted. When depth > 0, depth frames are skipped in the call stack and the final frame is treated like the original callee to Info.

func InfoDepthf

func InfoDepthf(depth int, format string, args ...any)

InfoDepthf acts as InfoDepth but with format string.

func Infof

func Infof(format string, args ...any)

Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func Infoln

func Infoln(args ...any)

Infoln logs to the INFO log. Arguments are handled in the manner of fmt.Println; a newline is appended if missing.

func Init

func Init(verbosity Level)

Init initializes the logging. The logger only outputs messages that are greater than or equal to the given severity. The log messages are written to output which be, for example, os.Stdout or a file. By default, the logger writes to os.Stderr.

func Warning

func Warning(args ...any)

Warning logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.

func WarningDepth

func WarningDepth(depth int, args ...any)

WarningDepth acts as Warning but uses depth to determine which call frame to log. WarningDepth(0, "msg") is the same as Warning("msg").

func WarningDepthf

func WarningDepthf(depth int, format string, args ...any)

WarningDepthf acts as Warningf but uses depth to determine which call frame to log. WarningDepthf(0, "msg") is the same as Warningf("msg").

func Warningf

func Warningf(format string, args ...any)

Warningf logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.

func Warningln

func Warningln(args ...any)

Warningln logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Println; a newline is appended if missing.

Types

type Level

type Level int

Level specifies a level of verbosity.

type Verbose

type Verbose bool

Verbose is a boolean type that implements the logging functions and executes them if the logger has the correct verbosity level set.

func V

func V(l Level) Verbose

V reports whether the verbosity level is set to at least the requested level. The returned value is a boolean of type verbose, which implements Info, Infoln and Infof. These methods will write to the INFO log if called. Thus, one may write either

if alog.V(2) { alog.Info("log this") }

or

alog.V(2).Info("log this")

The second form is shorter but the first is cheaper if logging is off because it does not evaluate its arguments.

Whether an individual call to V generates a log record depends on the verbosityLevel variable that is set when alog is initialized. If the level in the call to V is at most the value of verbosityLevel, the V call will log.

func (Verbose) Info

func (v Verbose) Info(args ...any)

Info is equivalent to the global Info function, guarded by the value of v. See the documentation of V for usage.

func (Verbose) InfoDepth

func (v Verbose) InfoDepth(depth int, args ...any)

InfoDepth is equivalent to the global InfoDepth function, guarded by the value of v. See the documentation of V for usage.

func (Verbose) InfoDepthf

func (v Verbose) InfoDepthf(depth int, format string, args ...any)

InfoDepthf is equivalent to the global InfoDepthf function, guarded by the value of v. See the documentation of V for usage.

func (Verbose) Infof

func (v Verbose) Infof(format string, args ...any)

Infof is equivalent to the global Infof function, guarded by the value of v. See the documentation of V for usage.

func (Verbose) Infoln

func (v Verbose) Infoln(args ...any)

Infoln is equivalent to the global Infoln function, guarded by the value of v. See the documentation of V for usage.

Directories

Path Synopsis
Package severity contains utilities for log severity.
Package severity contains utilities for log severity.
Package sink has the sinks for logging.
Package sink has the sinks for logging.

Jump to

Keyboard shortcuts

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