logger

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2025 License: Apache-2.0 Imports: 6 Imported by: 10

Documentation

Index

Constants

View Source
const (
	RequestContextKey string = "RequestContext"
)

Variables

This section is empty.

Functions

func AddMiddleLayers

func AddMiddleLayers(middlelayers ...MiddleLayer)

func Debug

func Debug(ctx context.Context, format string, a ...any)

func Error

func Error(ctx context.Context, format string, a ...any)

func Fatal

func Fatal(ctx context.Context, format string, a ...any)

func Info

func Info(ctx context.Context, format string, a ...any)

func Infof

func Infof(ctx context.Context, format string, fields *Fields)

func Infow

func Infow(ctx context.Context, message string, fs *Fields)

func Panic

func Panic(ctx context.Context, format string, a ...any)

func Warn

func Warn(ctx context.Context, format string, a ...any)

Types

type BaseLogger added in v1.2.0

type BaseLogger interface {
	Info(ctx context.Context, format string, a ...any)
	Error(ctx context.Context, format string, a ...any)
	Warn(ctx context.Context, format string, a ...any)
	Debug(ctx context.Context, format string, a ...any)
	Panic(ctx context.Context, format string, a ...any)
	Fatal(ctx context.Context, format string, a ...any)
}

type Build added in v1.2.0

type Build string
const (
	// BuildProd : prod build
	BuildProd Build = "prod"
	// BuildDev : dev build
	BuildDev Build = "dev"
)

type Config

type Config struct {
	AppName string   `yaml:"AppName" json:"AppName" name:"AppName" type:"string" description:"Application Name" required:"true"`
	Build   Build    `yaml:"Build" json:"Build" name:"Build" type:"choice" description:"Build Type" choices:"prod,dev"`
	Level   LogLevel `yaml:"Level" json:"Level" name:"Level" type:"choice" description:"Log Level" choices:"debug,info,warn,error,panic,fatal"`
}

Build : if prod it will set to prod else dev

func (Config) InitiateLogger

func (c Config) InitiateLogger() error

type Field added in v1.2.0

type Field struct {
	Key   string
	Value any
}

func NewField added in v1.2.0

func NewField(key string, value any) *Field

type Fields

type Fields struct {
	// contains filtered or unexported fields
}

func NewFields added in v1.2.0

func NewFields() *Fields

func RequestMiddleLayer

func RequestMiddleLayer(ctx context.Context, msg string, fields *Fields) (context.Context, string, *Fields)

func (*Fields) AddField

func (f *Fields) AddField(key string, value any) *Fields

type LogLevel

type LogLevel string
const (
	DebugLevel LogLevel = "debug"

	// InfoLevel is the default logging priority.
	InfoLevel LogLevel = "info"

	// WarnLevel logs are more important than Info, but don't need individual
	// human review.
	WarnLevel LogLevel = "warn"

	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel LogLevel = "error"

	// DPanicLevel logs are particularly important errors. In development the
	// logger panics after writing the message.
	PanicLevel LogLevel = "panic"

	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel LogLevel = "fatal"
)

type Logger added in v1.2.0

type Logger interface {
	BaseLogger
	Infof(ctx context.Context, format string, fields *Fields)
	Debugf(ctx context.Context, format string, fields *Fields)
	Errorf(ctx context.Context, format string, fields *Fields)
	Warnf(ctx context.Context, format string, fields *Fields)
	Panicf(ctx context.Context, format string, fields *Fields)
	Fatalf(ctx context.Context, format string, fields *Fields)
	AddMiddleLayers(middlelayers ...MiddleLayer)
	ReplaceMiddleLayers(middlelayers ...MiddleLayer)
	ChangeConfig(config *Config) error
}

func NewLogger added in v1.2.0

func NewLogger(config *Config, middleLayers ...MiddleLayer) (Logger, error)

type MiddleLayer

type MiddleLayer func(ctx context.Context, msg string, fields *Fields) (context.Context, string, *Fields)

type RequestContext

type RequestContext struct {
	SessionID     string
	RequestID     string
	ClientAppID   string
	UserID        string
	TransactionID string
	Method        string
	URI           string
	APIStartTime  time.Time
	IP            string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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