logger

package
v1.17.2 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: CC0-1.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	TraceLevelString = "trace"
	DebugLevelString = "debug"
	InfoLevelString  = "info"
	WarnLevelString  = "warn"
	ErrorLevelString = "error"
	FatalLevelString = "fatal"
)

Log level

View Source
const DefaultTimeFormat = time.RFC3339

DefaultTimeFormat of logger

Variables

This section is empty.

Functions

func LevelToString

func LevelToString(l Level) string

LevelToString convert log level to readable string

Types

type Config

type Config struct {
	Level      Level
	AppName    string
	LogFile    string
	TimeFormat string
	CallerSkip int
	Caller     bool
	UseColor   bool
	UseJSON    bool
	StdLog     bool
	Debug      bool
}

Config of logger

func (*Config) OpenLogFile

func (c *Config) OpenLogFile() (*os.File, error)

OpenLogFile tries to open the log file (creates it if not exists) in write-only/append mode and return it Note: the func return nil for both *os.File and error if the file name is empty string

type Engine

type Engine string

Engine of logger

const (
	Logrus  Engine = "logrus"
	Zerolog Engine = "zerolog"
)

Logger engine option

type KV

type KV = map[string]interface{}

KV is a type for logging with more information this used by ...WithFields function

type Level

type Level int

Level of log

const (
	TraceLevel Level = iota
	DebugLevel
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
)

list of log level

func StringToLevel

func StringToLevel(level string) Level

StringToLevel to set string to level

type Logger

type Logger interface {
	SetLevel(level Level)
	Debug(args ...interface{})
	Debugln(args ...interface{})
	Debugf(format string, args ...interface{})
	DebugWithFields(msg string, KV KV)
	Info(args ...interface{})
	Infoln(args ...interface{})
	Infof(format string, args ...interface{})
	InfoWithFields(msg string, KV KV)
	Warn(args ...interface{})
	Warnln(args ...interface{})
	Warnf(format string, args ...interface{})
	WarnWithFields(msg string, KV KV)
	Error(args ...interface{})
	Errorln(args ...interface{})
	Errorf(format string, args ...interface{})
	ErrorWithFields(msg string, KV KV)
	Errors(err error)
	Fatal(args ...interface{})
	Fatalln(args ...interface{})
	Fatalf(format string, args ...interface{})
	FatalWithFields(msg string, KV KV)
	IsValid() bool // IsValid check if Logger is created using constructor

	StdTrace(requestID string, contextID string, err error, metadata interface{}, message string)
	StdTracef(requestID string, contextID string, err error, metadata interface{}, format string, args ...interface{})
	StdDebug(requestID string, contextID string, err error, metadata interface{}, message string)
	StdDebugf(requestID string, contextID string, err error, metadata interface{}, format string, args ...interface{})
	StdInfo(requestID string, contextID string, err error, metadata interface{}, message string)
	StdInfof(requestID string, contextID string, err error, metadata interface{}, format string, args ...interface{})
	StdWarn(requestID string, contextID string, err error, metadata interface{}, message string)
	StdWarnf(requestID string, contextID string, err error, metadata interface{}, format string, args ...interface{})
	StdError(requestID string, contextID string, err error, metadata interface{}, message string)
	StdErrorf(requestID string, contextID string, err error, metadata interface{}, format string, args ...interface{})
	StdFatal(requestID string, contextID string, err error, metadata interface{}, message string)
	StdFatalf(requestID string, contextID string, err error, metadata interface{}, format string, args ...interface{})
}

Logger interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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