log

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: MIT, MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DebugLevel = Level(logger.DebugLevel)
	InfoLevel  = Level(logger.InfoLevel)
	WarnLevel  = Level(logger.WarnLevel)
	ErrorLevel = Level(logger.ErrorLevel)
	FatalLevel = Level(logger.FatalLevel)
)

Level option

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

Debug prints debug level log like log.Print

func DebugWithFields

func DebugWithFields(msg string, fields map[string]interface{})

DebugWithFields prints debug level log with additional fields. useful when output is in json format

func Debugf

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

Debugf prints debug level log like log.Printf

func Debugln

func Debugln(args ...interface{})

Debugln prints debug level log like log.Println

func Error

func Error(args ...interface{})

Error prints error level log like log.Print

func ErrorWithFields

func ErrorWithFields(msg string, fields map[string]interface{})

ErrorWithFields prints error level log with additional fields. useful when output is in json format

func Errorf

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

Errorf prints error level log like log.Printf

func Errorln

func Errorln(args ...interface{})

Errorln prints error level log like log.Println

func Errors

func Errors(err error)

Errors can handle error from tdk/x/go/errors package

func Fatal

func Fatal(args ...interface{})

Fatal prints fatal level log like log.Print

func FatalWithFields

func FatalWithFields(msg string, fields map[string]interface{})

FatalWithFields prints fatal level log with additional fields. useful when output is in json format

func Fatalf

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

Fatalf prints fatal level log like log.Printf

func Fatalln

func Fatalln(args ...interface{})

Fatalln prints fatal level log like log.Println

func Info

func Info(args ...interface{})

Info prints info level log like log.Print

func InfoWithFields

func InfoWithFields(msg string, fields map[string]interface{})

InfoWithFields prints info level log with additional fields. useful when output is in json format

func Infof

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

Infof prints info level log like log.Printf

func Infoln

func Infoln(args ...interface{})

Infoln prints info level log like log.Println

func Print

func Print(v ...interface{})

Print info level log like log.Print

func Printf

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

Printf info level log like log.Printf

func Println

func Println(v ...interface{})

Println info level log like log.Println

func SetConfig

func SetConfig(config *Config) error

SetConfig creates new default (info & debug) logger based on given config

func SetLevel

func SetLevel(level Level)

SetLevel adjusts log level threshold. Only log with level higher or equal with this level will be printed

func SetLogger

func SetLogger(level Level, lgr Logger) error

SetLogger will set the logger configuration on certain level

func Warn

func Warn(args ...interface{})

Warn prints warn level log like log.Print

func WarnWithFields

func WarnWithFields(msg string, fields map[string]interface{})

WarnWithFields prints warn level log with additional fields. useful when output is in json format

func Warnf

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

Warnf prints warn level log like log.Printf

func Warnln

func Warnln(args ...interface{})

Warnln prints warn level log like log.Println

Types

type Config

type Config struct {
	// Level log level, default: debug
	Level Level

	// Format of the log's time field
	// default RFC3339="2006-01-02T15:04:05Z07:00"
	TimeFormat string

	// AppName is the application name this log belong to
	AppName string

	// Caller, option to print caller line numbers.
	// make sure you understand the overhead when use this
	Caller bool

	// LogFile is output file for log other than debug log
	// this is not needed by default,
	// application is expected to run in containerized environment
	LogFile string

	// DebugFile is output file for debug log
	// this is not needed by default,
	// application is expected to run in containerized environment
	DebugFile string

	// UseColor, option to colorize log in console.
	UseColor bool

	// UseJSON, option to print in json format.
	UseJSON bool
}

Config of log

type Level

type Level logger.Level

Level logger

type Logger

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

Logger interface

func NewLogger

func NewLogger(config *Config) (Logger, error)

NewLogger will create new logger with specific configuration the return must be set using set logger to register it

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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