log

package
v0.0.0-...-e098d20 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package log implements a leveled logging system. It checks the current log level and decides whether to print the logging texts or ignore them.

Index

Constants

View Source
const DefaultLevel = WARNING

DefaultLevel defines the default log level

Variables

View Source
var (
	// SetLevel is the wrapper for the global logger
	SetLevel = globalLevel.SetLevel

	// Level is the wrapper for the global logger
	Level = globalLevel.Level
)
View Source
var LevelStr = []string{
	DEBUG:   "DEBUG",
	INFO:    "INFO",
	WARNING: "WARN",
	ERROR:   "ERROR",
}

LevelStr represents the log levels in strings

Functions

func Debug

func Debug(args ...interface{})

Debug prints the log message in the specified level

func Debugf

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

Debugf formats the log message with specified args and print it in the specified level

func Error

func Error(args ...interface{})

Error prints the log message in the specified level

func Errorf

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

Errorf formats the log message with specified args and print it in the specified level

func Info

func Info(args ...interface{})

Info prints the log message in the specified level

func Infof

func Infof(msg string, args ...interface{})

Infof formats the log message with specified args and print it in the specified level

func Log

func Log(level LogLevel, args ...interface{})

Log prints the log message in the specified level

func Logf

func Logf(level LogLevel, msg string, args ...interface{})

Logf formats the log message with specified args and print it in the specified level

func SetLevelFromStr

func SetLevelFromStr(s string)

SetLevelFromStr parses the input string to a LogLevel and change the level of the global logger accordingly.

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output destination for the internal logger.

func Warning

func Warning(args ...interface{})

Warning prints the log message in the specified level

func Warningf

func Warningf(msg string, args ...interface{})

Warningf formats the log message with specified args and print it in the specified level

Types

type LogLevel

type LogLevel uint8

LogLevel is a type that defines the log level.

const (
	DEBUG LogLevel = iota
	INFO
	WARNING
	ERROR
)

log levels

func StrToLevel

func StrToLevel(e string) (LogLevel, error)

StrToLevel converts a log level in string format (e.g., "DEBUG") to the corresponding log level in LogLevel type. It returns ERROR (the highest level) and an error for invalid log level strings.

func ToLogLevel

func ToLogLevel(level string) (LogLevel, bool)

ToLogLevel converts a string to a log level, or returns false for any error

Jump to

Keyboard shortcuts

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