logging

package
v0.0.0-...-48df7e4 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2025 License: MIT Imports: 6 Imported by: 0

README

Logging Package

This package implements structured logging for the application:

  • JSON formatted logs
  • Log levels and filtering
  • Request/response logging
  • Audit logging and security events
  • External logging integration with an asynchronous worker

Configuration Options

The external logging integration supports the following configuration options:

  • Buffer Size: The maximum number of log entries that can be stored in the buffer before being sent. Default: 100.
  • Batch Size: The number of log entries sent in a single batch to the external logging system. Default: 10.
  • Retry Policy (maxAttempts): The maximum number of attempts to send a batch before falling back to local logging. Default: 3.
  • Retry Interval: The interval between retry attempts. Default: 5s.
  • Fallback to Local Logging: If enabled, failed batches after all attempts are sent to the local logger.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(ip string) zap.Field

ClientIP returns a field for client IP address

func CorrelationID

func CorrelationID(id string) zap.Field

CorrelationID returns a field for correlation ID

func GetCorrelationID

func GetCorrelationID(ctx context.Context) (string, bool)

GetCorrelationID retrieves the correlation ID from context

func GetRequestID

func GetRequestID(ctx context.Context) (string, bool)

GetRequestID retrieves the request ID from context

func NewChildLogger

func NewChildLogger(parent *zap.Logger, component string) *zap.Logger

NewChildLogger creates a child logger with a component field

func NewLogger

func NewLogger(level, format, filePath string) (*zap.Logger, error)

NewLogger creates a zap.Logger with the specified level, format, and optional file output. level can be debug, info, warn, or error. format can be json or console. If filePath is empty, logs are written to stdout.

func ProjectID

func ProjectID(id string) zap.Field

ProjectID returns a field for project ID

func RequestFields

func RequestFields(requestID, method, path string, statusCode, durationMs int) []zap.Field

RequestFields returns fields for HTTP request logging

func TokenID

func TokenID(token string) zap.Field

TokenID returns a field for token ID (obfuscated for security)

func WithCorrelationContext

func WithCorrelationContext(ctx context.Context, logger *zap.Logger) *zap.Logger

WithCorrelationContext adds correlation ID from context to logger if present

func WithCorrelationID

func WithCorrelationID(ctx context.Context, correlationID string) context.Context

WithCorrelationID adds a correlation ID to the context

func WithRequestContext

func WithRequestContext(ctx context.Context, logger *zap.Logger) *zap.Logger

WithRequestContext adds request ID from context to logger if present

func WithRequestID

func WithRequestID(ctx context.Context, requestID string) context.Context

WithRequestID adds a request ID to the context

Types

This section is empty.

Jump to

Keyboard shortcuts

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