Documentation
¶
Index ¶
- func GetCallerInfo(skip int) (string, int, string)
- func WithEnvironment(environment string) func(*Config)
- func WithService(serviceName string) func(*Config)
- func WithVersion(version string) func(*Config)
- type Config
- type LogLevel
- type RequestContext
- type StructuredLogger
- func (sl *StructuredLogger) DebugWithContext(msg string, args ...any)
- func (sl *StructuredLogger) ErrorWithContext(msg string, err error, args ...any)
- func (sl *StructuredLogger) InfoWithContext(msg string, args ...any)
- func (sl *StructuredLogger) LogAPIUsage(endpoint, method, userID string, requestSize, responseSize int64, ...)
- func (sl *StructuredLogger) LogAuditEvent(action, resource, userID string, metadata map[string]interface{})
- func (sl *StructuredLogger) LogBusinessEvent(eventType string, metadata map[string]interface{})
- func (sl *StructuredLogger) LogFormat(level LogLevel, msg string, obj interface{})
- func (sl *StructuredLogger) LogHTTPRequest(method, path string, statusCode int, duration time.Duration, size int64)
- func (sl *StructuredLogger) LogOperation(operationName string, fn func() error) error
- func (sl *StructuredLogger) LogPerformance(operationName string, duration time.Duration, metadata map[string]interface{})
- func (sl *StructuredLogger) LogResourceUsage(cpuPercent, memoryMB, diskUsagePercent float64)
- func (sl *StructuredLogger) LogSecurityEvent(eventType, description, severity string, metadata map[string]interface{})
- func (sl *StructuredLogger) LogSystemMetrics(metrics map[string]interface{})
- func (sl *StructuredLogger) WarnWithContext(msg string, args ...any)
- func (sl *StructuredLogger) WithComponent(component string) *StructuredLogger
- func (sl *StructuredLogger) WithRequest(ctx *RequestContext) *StructuredLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithEnvironment ¶
WithEnvironment creates a config option to set the environment
func WithService ¶
WithService creates a config option to set the service name
func WithVersion ¶
WithVersion creates a config option to set the service version
Types ¶
type Config ¶
type Config struct {
Level LogLevel `json:"level"`
Format string `json:"format"` // "json" or "text"
ServiceName string `json:"service_name"`
Version string `json:"version"`
Environment string `json:"environment"`
Component string `json:"component"`
AddSource bool `json:"add_source"`
TimeFormat string `json:"time_format"`
}
func DefaultConfig ¶
type RequestContext ¶
type StructuredLogger ¶
func NewLogger ¶
func NewLogger(serviceName, level string) *StructuredLogger
func NewStructuredLogger ¶
func NewStructuredLogger(config Config) *StructuredLogger
func NewStructuredLoggerWithOptions ¶
func NewStructuredLoggerWithOptions(options ...func(*Config)) *StructuredLogger
NewStructuredLogger creates a new structured logger with functional options
func (*StructuredLogger) DebugWithContext ¶
func (sl *StructuredLogger) DebugWithContext(msg string, args ...any)
func (*StructuredLogger) ErrorWithContext ¶
func (sl *StructuredLogger) ErrorWithContext(msg string, err error, args ...any)
func (*StructuredLogger) InfoWithContext ¶
func (sl *StructuredLogger) InfoWithContext(msg string, args ...any)
func (*StructuredLogger) LogAPIUsage ¶
func (sl *StructuredLogger) LogAPIUsage(endpoint, method, userID string, requestSize, responseSize int64, duration time.Duration)
func (*StructuredLogger) LogAuditEvent ¶
func (sl *StructuredLogger) LogAuditEvent(action, resource, userID string, metadata map[string]interface{})
func (*StructuredLogger) LogBusinessEvent ¶
func (sl *StructuredLogger) LogBusinessEvent(eventType string, metadata map[string]interface{})
func (*StructuredLogger) LogFormat ¶
func (sl *StructuredLogger) LogFormat(level LogLevel, msg string, obj interface{})
func (*StructuredLogger) LogHTTPRequest ¶
func (*StructuredLogger) LogOperation ¶
func (sl *StructuredLogger) LogOperation(operationName string, fn func() error) error
func (*StructuredLogger) LogPerformance ¶
func (sl *StructuredLogger) LogPerformance(operationName string, duration time.Duration, metadata map[string]interface{})
func (*StructuredLogger) LogResourceUsage ¶
func (sl *StructuredLogger) LogResourceUsage(cpuPercent, memoryMB, diskUsagePercent float64)
func (*StructuredLogger) LogSecurityEvent ¶
func (sl *StructuredLogger) LogSecurityEvent(eventType, description, severity string, metadata map[string]interface{})
func (*StructuredLogger) LogSystemMetrics ¶
func (sl *StructuredLogger) LogSystemMetrics(metrics map[string]interface{})
func (*StructuredLogger) WarnWithContext ¶
func (sl *StructuredLogger) WarnWithContext(msg string, args ...any)
func (*StructuredLogger) WithComponent ¶
func (sl *StructuredLogger) WithComponent(component string) *StructuredLogger
func (*StructuredLogger) WithRequest ¶
func (sl *StructuredLogger) WithRequest(ctx *RequestContext) *StructuredLogger
Click to show internal directories.
Click to hide internal directories.