Documentation
¶
Overview ¶
Package logging provides structured logging with trace ID support
Index ¶
- func DebugDefault(ctx context.Context, message string)
- func ErrorDefault(ctx context.Context, message string, err error)
- func FormatDuration(d time.Duration) string
- func GetRole(ctx context.Context) string
- func GetService(ctx context.Context) string
- func GetTraceID(ctx context.Context) string
- func GetUserID(ctx context.Context) string
- func InfoDefault(ctx context.Context, message string)
- func InitDefault(service, level, format string)
- func NewTraceID() string
- func WarnDefault(ctx context.Context, message string)
- func WithRole(ctx context.Context, role string) context.Context
- func WithService(ctx context.Context, service string) context.Context
- func WithTraceID(ctx context.Context, traceID string) context.Context
- func WithUserID(ctx context.Context, userID string) context.Context
- type ContextKey
- type Logger
- func (l *Logger) Debug(ctx context.Context, message string, fields map[string]interface{})
- func (l *Logger) Error(ctx context.Context, message string, err error, fields map[string]interface{})
- func (l *Logger) Fatal(ctx context.Context, message string, err error)
- func (l *Logger) Info(ctx context.Context, message string, fields map[string]interface{})
- func (l *Logger) LogAudit(ctx context.Context, action, resource, resourceID, result string)
- func (l *Logger) LogBlockchainTx(ctx context.Context, txHash, operation string, err error)
- func (l *Logger) LogCryptoOperation(ctx context.Context, operation string, success bool, err error)
- func (l *Logger) LogDatabaseQuery(ctx context.Context, query string, duration time.Duration, err error)
- func (l *Logger) LogErrorWithStack(ctx context.Context, err error, message string, fields map[string]interface{})
- func (l *Logger) LogPerformance(ctx context.Context, operation string, metrics map[string]interface{})
- func (l *Logger) LogRequest(ctx context.Context, method, path string, statusCode int, ...)
- func (l *Logger) LogSecurityEvent(ctx context.Context, eventType string, details map[string]interface{})
- func (l *Logger) LogServiceCall(ctx context.Context, targetService, method string, duration time.Duration, ...)
- func (l *Logger) Panic(ctx context.Context, message string, err error)
- func (l *Logger) SetOutput(output io.Writer)
- func (l *Logger) Warn(ctx context.Context, message string, fields map[string]interface{})
- func (l *Logger) WithContext(ctx context.Context) *logrus.Entry
- func (l *Logger) WithError(err error) *logrus.Entry
- func (l *Logger) WithFields(fields map[string]interface{}) *logrus.Entry
- func (l *Logger) WithTraceID(traceID string) *logrus.Entry
- func (l *Logger) WithUserID(userID string) *logrus.Entry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DebugDefault ¶
DebugDefault logs a debug message using the default logger
func ErrorDefault ¶
ErrorDefault logs an error message using the default logger
func FormatDuration ¶
Helper to format duration in milliseconds
func GetService ¶
GetService retrieves the service name from context
func GetTraceID ¶
GetTraceID retrieves the trace ID from context
func InfoDefault ¶
InfoDefault logs an info message using the default logger
func InitDefault ¶
func InitDefault(service, level, format string)
InitDefault initializes the default logger
func WarnDefault ¶
WarnDefault logs a warning message using the default logger
func WithService ¶
WithService adds a service name to the context
func WithTraceID ¶
WithTraceID adds a trace 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 ¶
Logger wraps logrus.Logger with additional functionality
func NewFromEnv ¶
NewFromEnv constructs a logger using LOG_LEVEL and LOG_FORMAT environment variables. Defaults to "info" and "json" when unset.
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) LogBlockchainTx ¶
LogBlockchainTx logs a blockchain transaction
func (*Logger) LogCryptoOperation ¶
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) WithContext ¶
WithContext creates a new logger entry with context values
func (*Logger) WithFields ¶
WithFields creates a new logger entry with custom fields
func (*Logger) WithTraceID ¶
WithTraceID creates a new logger entry with trace ID