log

package
v1.40.1 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: Apache-2.0 Imports: 9 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// LogPrefix is a prefix to include in each log line.
	LogPrefix = flag.String("logprefix", "> ", "Prefix to log lines before logged messages")
	// LogFileAndLine determines if the log lines will contain caller file name and line number.
	LogFileAndLine = flag.Bool("logcaller", true, "Logs filename and line number of callers to log")

	// Tests can override this to cover exit case.
	FatalExit = os.Exit
)

Functions

func ChangeFlagsDefault added in v1.39.0

func ChangeFlagsDefault(newDefault string, flagNames ...string)

ChangeFlagsDefault sets some flags to a different default.

func Critf

func Critf(format string, rest ...interface{})

Critf logs if Warning level is on.

func Debugf

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

Debugf logs if Debug level is on.

func Errf

func Errf(format string, rest ...interface{})

Errf logs if Warning level is on.

func FErrf added in v1.40.0

func FErrf(format string, rest ...interface{}) int

FErrF logs a fatal error and returns 1. meant for cli main functions written like: func main() { os.Exit(Main()) } and if err != nil { return log.FErrf("error: %v", err) } so they can be tested with testscript. See https://github.com/fortio/delta/ for example.

func Fatalf

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

Fatalf logs if Warning level is on and panics or exits.

func Infof

func Infof(format string, rest ...interface{})

Infof logs if Info level is on.

func Log

func Log(lvl Level) bool

Log returns true if a given level is currently logged.

func LogDebug

func LogDebug() bool

LogDebug shortcut for fortio.Log(fortio.Debug).

func LogVerbose

func LogVerbose() bool

LogVerbose shortcut for fortio.Log(fortio.Verbose).

func LogVf

func LogVf(format string, rest ...interface{})

LogVf logs if Verbose level is on.

func Logf

func Logf(lvl Level, format string, rest ...interface{})

Logf logs with format at the given level. 2 level of calls so it's always same depth for extracting caller file/line. Note that log.Logf(Fatal, "...") will not panic or exit, only log.Fatalf() does.

func Printf added in v1.32.0

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

Printf forwards to the underlying go logger to print (with only timestamp prefixing).

func SetFlagDefaultsForClientTools added in v1.11.0

func SetFlagDefaultsForClientTools()

SetFlagDefaultsForClientTools changes the default value of -logprefix and -logcaller to make output without caller and prefix, a default more suitable for command line tools (like dnsping). Needs to be called before flag.Parse(). Caller could also use log.Printf instead of changing this if not wanting to use levels. Also makes log.Fatalf just exit instead of panic.

func SetFlags

func SetFlags(f int)

SetFlags forwards flags to the system logger.

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output to a different writer (forwards to system logger).

func Warnf

func Warnf(format string, rest ...interface{})

Warnf logs if Warning level is on.

Types

type Level

type Level int32

Level is the level of logging (0 Debug -> 6 Fatal).

const (
	Debug Level = iota
	Verbose
	Info
	Warning
	Error
	Critical
	Fatal
)

Log levels. Go can't have variable and function of the same name so we keep medium length (Dbg,Info,Warn,Err,Crit,Fatal) names for the functions.

func GetLogLevel

func GetLogLevel() Level

GetLogLevel returns the currently configured LogLevel.

func LevelByName

func LevelByName(str string) Level

LevelByName returns the LogLevel by its name.

func SetLogLevel

func SetLogLevel(lvl Level) Level

SetLogLevel sets the log level and returns the previous one.

func SetLogLevelQuiet added in v0.6.4

func SetLogLevelQuiet(lvl Level) Level

SetLogLevelQuiet sets the log level and returns the previous one but does not log the change of level itself.

func ValidateLevel added in v1.5.0

func ValidateLevel(str string) (Level, error)

ValidateLevel returns error if the level string is not valid.

func (Level) String

func (l Level) String() string

String returns the string representation of the level.

type LoggerI added in v1.4.3

type LoggerI interface {
	Printf(format string, rest ...interface{})
}

LoggerI defines a log.Logger like interface for simple logging.

func Logger added in v1.4.3

func Logger() LoggerI

Logger returns a LoggerI (standard logger compatible) that can be used for simple logging.

Jump to

Keyboard shortcuts

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