log

package
v0.0.0-...-90deddd Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: Apache-2.0 Imports: 4 Imported by: 16

Documentation

Overview

Package log implements leveling and teeing on top of Go's standard logs package. As with the standard log package, this package defines a standard logger available as a package global and via package functions.

Index

Constants

This section is empty.

Variables

Std is the standard global logger. It is used by the package level logging functions.

Functions

func At

func At(level Level) bool

At returns true when the standard logger is at or above the provided level.

func Debug

func Debug(v ...interface{})

Debug formats a message in the manner of fmt.Sprint and logs it to the standard (debug) logger.

func Debugf

func Debugf(format string, args ...interface{})

Debugf formats a message in the manner of fmt.Sprintf and logs it to the standard (debug) logger.

func Error

func Error(v ...interface{})

Error formats a message in the manner of fmt.Sprint and logs it to the standard (error) logger.

func Errorf

func Errorf(format string, args ...interface{})

Errorf formats a message in the manner of fmt.Sprintf and logs it to the standard (error) logger.

func Fatal

func Fatal(v ...interface{})

Fatal formats a message in the manner of fmt.Print, outputs it to the standard outputter (always), and then calls os.Exit(1).

func Fatalf

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

Fatalf formats a message in the manner of fmt.Printf, outputs it to the standard outputter (always), and then calls os.Exit(1).

func Print

func Print(v ...interface{})

Print formats a message in the manner of fmt.Sprint and logs it to the standard logger.

func Printf

func Printf(format string, args ...interface{})

Printf formats a message in the manner of fmt.Sprintf and logs it to the standard logger.

Types

type Level

type Level int

Level defines the level of logging. Higher levels are more verbose.

const (
	// OffLevel turns logging off.
	OffLevel Level = iota
	// ErrorLevel outputs only error messages.
	ErrorLevel
	// InfoLevel is the standard error level.
	InfoLevel
	// DebugLevel outputs detailed debugging output.
	DebugLevel
)

func LevelFromString

func LevelFromString(level string) Level

func (Level) String

func (l Level) String() string

type Logger

type Logger struct {
	// Outputter receives all log messages at or below the Logger's
	// current level.
	Outputter
	// Level defines the publishing level of this Logger.
	Level Level

	Parent *Logger
	// contains filtered or unexported fields
}

A Logger receives log messages at multiple levels, and publishes those messages to its outputter if the level (or logger) is active. Nil Loggers ignore all log messages.

func New

func New(out Outputter, level Level) *Logger

New creates a new Logger that publishes messsages at or below the provided level to the provided outputter.

func NewWithLevelPrefix

func NewWithLevelPrefix(out Outputter) *Logger

NewWithLevelPrefix creates a new Logger that prefixes each log with the logging level it was output with. Logs at all levels are output.

func (*Logger) At

func (l *Logger) At(level Level) bool

At tells whether the logger is at or below the provided level.

func (*Logger) Debug

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

Debug formats a message in the manner of fmt.Print and publishes it to the logger at DebugLevel.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

Debugf formats a message in the manner of fmt.Printf and publishes it to the logger at DebugLevel.

func (*Logger) Error

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

Error formats a message in the manner of fmt.Print and publishes it to the logger at ErrorLevel.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

Errorf formats a message in the manner of fmt.Printf and publishes it to the logger at ErrorLevel.

func (*Logger) Print

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

Print formats a message in the manner of fmt.Print and publishes it to the logger at InfoLevel.

func (*Logger) Printf

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

Printf formats a message in the manner of fmt.Printf and publishes it to the logger at InfoLevel.

func (*Logger) Tee

func (l *Logger) Tee(out Outputter, prefix string) *Logger

Tee constructs a new logger that tees its output to the provided outputter and Parent logger. Messages sent to the Parent are prefixed with the provided prefix string. Out may be nil, in which cases messages are published to the Parent only.

type Outputter

type Outputter interface {
	Output(calldepth int, s string) error
}

An Outputter receives published log messages. Go's *log.Logger implements Outputter.

func MultiOutputter

func MultiOutputter(outputters ...Outputter) Outputter

MultiOutputter returns an Outputter that outputs each message to all the provided outputters.

Jump to

Keyboard shortcuts

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