logger

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: Apache-2.0 Imports: 8 Imported by: 10

Documentation

Index

Constants

This section is empty.

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)

func WithRequestMiddleware added in v1.2.3

func WithRequestMiddleware(next http.Handler) http.Handler

Middleware to add Request ID

func WithRequestTimeMiddleware added in v1.2.3

func WithRequestTimeMiddleware(next http.Handler) http.Handler

request time middleware

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"`
	// contains filtered or unexported fields
}

Build : if prod it will set to prod else dev

func (Config) InitiateLogger

func (c Config) InitiateLogger() error

type ContextKey added in v1.2.2

type ContextKey string
const (
	RequestContextKey ContextKey = "RequestContext"
)

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 {
	RequestID string
	Client    string
	UserID    string
	Method    string
	URI       string
	IP        string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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