logging

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package logging provides structured logging with trace ID support

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DebugDefault

func DebugDefault(ctx context.Context, message string)

DebugDefault logs a debug message using the default logger

func ErrorDefault

func ErrorDefault(ctx context.Context, message string, err error)

ErrorDefault logs an error message using the default logger

func FormatDuration

func FormatDuration(d time.Duration) string

Helper to format duration in milliseconds

func GetRole

func GetRole(ctx context.Context) string

GetRole retrieves the user role from context

func GetService

func GetService(ctx context.Context) string

GetService retrieves the service name from context

func GetTraceID

func GetTraceID(ctx context.Context) string

GetTraceID retrieves the trace ID from context

func GetUserID

func GetUserID(ctx context.Context) string

GetUserID retrieves the user ID from context

func InfoDefault

func InfoDefault(ctx context.Context, message string)

InfoDefault logs an info message using the default logger

func InitDefault

func InitDefault(service, level, format string)

InitDefault initializes the default logger

func NewTraceID

func NewTraceID() string

NewTraceID generates a new trace ID

func WarnDefault

func WarnDefault(ctx context.Context, message string)

WarnDefault logs a warning message using the default logger

func WithRole

func WithRole(ctx context.Context, role string) context.Context

WithRole adds a user role to the context

func WithService

func WithService(ctx context.Context, service string) context.Context

WithService adds a service name to the context

func WithTraceID

func WithTraceID(ctx context.Context, traceID string) context.Context

WithTraceID adds a trace ID to the context

func WithUserID

func WithUserID(ctx context.Context, userID string) context.Context

WithUserID adds a user ID to the context

Types

type ContextKey

type ContextKey string

ContextKey is the type for context keys

const (
	// TraceIDKey is the context key for trace ID
	TraceIDKey ContextKey = "trace_id"
	// UserIDKey is the context key for user ID
	UserIDKey ContextKey = "user_id"
	// RoleKey is the context key for user role
	RoleKey ContextKey = "role"
	// ServiceKey is the context key for service name
	ServiceKey ContextKey = "service"
)

type Logger

type Logger struct {
	*logrus.Logger
	// contains filtered or unexported fields
}

Logger wraps logrus.Logger with additional functionality

func Default

func Default() *Logger

Default returns the default logger

func New

func New(service, level, format string) *Logger

New creates a new Logger instance

func NewFromEnv

func NewFromEnv(service string) *Logger

NewFromEnv constructs a logger using LOG_LEVEL and LOG_FORMAT environment variables. Defaults to "info" and "json" when unset.

func (*Logger) Debug

func (l *Logger) Debug(ctx context.Context, message string, fields map[string]interface{})

Debug logs a debug message (only in development)

func (*Logger) Error

func (l *Logger) Error(ctx context.Context, message string, err error, fields map[string]interface{})

Error logs an error message

func (*Logger) Fatal

func (l *Logger) Fatal(ctx context.Context, message string, err error)

Fatal logs a fatal error and exits

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, message string, fields map[string]interface{})

Info logs an info message

func (*Logger) LogAudit

func (l *Logger) LogAudit(ctx context.Context, action, resource, resourceID, result string)

LogAudit logs an audit event

func (*Logger) LogBlockchainTx

func (l *Logger) LogBlockchainTx(ctx context.Context, txHash, operation string, err error)

LogBlockchainTx logs a blockchain transaction

func (*Logger) LogCryptoOperation

func (l *Logger) LogCryptoOperation(ctx context.Context, operation string, success bool, err error)

LogCryptoOperation logs a cryptographic operation

func (*Logger) LogDatabaseQuery

func (l *Logger) LogDatabaseQuery(ctx context.Context, query string, duration time.Duration, err error)

LogDatabaseQuery logs a database query

func (*Logger) LogErrorWithStack

func (l *Logger) LogErrorWithStack(ctx context.Context, err error, message string, fields map[string]interface{})

LogErrorWithStack logs an error with additional context

func (*Logger) LogPerformance

func (l *Logger) LogPerformance(ctx context.Context, operation string, metrics map[string]interface{})

LogPerformance logs performance metrics

func (*Logger) LogRequest

func (l *Logger) LogRequest(ctx context.Context, method, path string, statusCode int, duration time.Duration)

LogRequest logs an HTTP request

func (*Logger) LogSecurityEvent

func (l *Logger) LogSecurityEvent(ctx context.Context, eventType string, details map[string]interface{})

LogSecurityEvent logs a security-related event

func (*Logger) LogServiceCall

func (l *Logger) LogServiceCall(ctx context.Context, targetService, method string, duration time.Duration, err error)

LogServiceCall logs a service-to-service call

func (*Logger) Panic

func (l *Logger) Panic(ctx context.Context, message string, err error)

Panic logs a panic and panics

func (*Logger) SetOutput

func (l *Logger) SetOutput(output io.Writer)

SetOutput sets the logger output

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, message string, fields map[string]interface{})

Warn logs a warning message

func (*Logger) WithContext

func (l *Logger) WithContext(ctx context.Context) *logrus.Entry

WithContext creates a new logger entry with context values

func (*Logger) WithError

func (l *Logger) WithError(err error) *logrus.Entry

WithError creates a new logger entry with error

func (*Logger) WithFields

func (l *Logger) WithFields(fields map[string]interface{}) *logrus.Entry

WithFields creates a new logger entry with custom fields

func (*Logger) WithTraceID

func (l *Logger) WithTraceID(traceID string) *logrus.Entry

WithTraceID creates a new logger entry with trace ID

func (*Logger) WithUserID

func (l *Logger) WithUserID(userID string) *logrus.Entry

WithUserID creates a new logger entry with user ID

Jump to

Keyboard shortcuts

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