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
- func Error(args ...any)
- func ErrorDepth(depth int, args ...any)
- func ErrorDepthf(depth int, format string, args ...any)
- func Errorf(format string, args ...any)
- func Errorln(args ...any)
- func Info(args ...any)
- func InfoDepth(depth int, args ...any)
- func InfoDepthf(depth int, format string, args ...any)
- func Infof(format string, args ...any)
- func Infoln(args ...any)
- func Init(verbosity Level)
- func Warning(args ...any)
- func WarningDepth(depth int, args ...any)
- func WarningDepthf(depth int, format string, args ...any)
- func Warningf(format string, args ...any)
- func Warningln(args ...any)
- type Level
- type Verbose
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
InfoDepthf acts as InfoDepth but with format string.
func Infof ¶
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 ¶
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 ¶
WarningDepthf acts as Warningf but uses depth to determine which call frame to log. WarningDepthf(0, "msg") is the same as Warningf("msg").
Types ¶
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 ¶
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 ¶
Info is equivalent to the global Info function, guarded by the value of v. See the documentation of V for usage.
func (Verbose) InfoDepth ¶
InfoDepth is equivalent to the global InfoDepth function, guarded by the value of v. See the documentation of V for usage.
func (Verbose) InfoDepthf ¶
InfoDepthf is equivalent to the global InfoDepthf function, guarded by the value of v. See the documentation of V for usage.