logging

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package logging provides structured logging for Typosentinel This package implements a comprehensive logging system with multiple outputs and formats

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Format

type Format string

Format represents log output formats

const (
	FormatJSON Format = "json"
	FormatText Format = "text"
)

type Level

type Level string

Level represents log levels

const (
	LevelDebug Level = "debug"
	LevelInfo  Level = "info"
	LevelWarn  Level = "warn"
	LevelError Level = "error"
)

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger implements the interfaces.Logger interface

func NewLogger

func NewLogger(cfg *config.LoggingConfig) (*Logger, error)

NewLogger creates a new logger instance

func (*Logger) Close

func (l *Logger) Close() error

Close closes the logger and any associated resources

func (*Logger) Debug

func (l *Logger) Debug(message string, fields ...interfaces.LogField)

Debug logs a debug message

func (*Logger) Error

func (l *Logger) Error(message string, fields ...interfaces.LogField)

Error logs an error message

func (*Logger) ErrorWithErr

func (l *Logger) ErrorWithErr(message string, err error, fields ...interfaces.LogField)

ErrorWithErr logs an error message with error details

func (*Logger) Fatal

func (l *Logger) Fatal(message string, fields ...interfaces.LogField)

Fatal logs a fatal message and exits

func (*Logger) GetLevel

func (l *Logger) GetLevel() string

GetLevel returns the current log level

func (*Logger) GetStats

func (l *Logger) GetStats() map[string]interface{}

GetStats returns logging statistics

func (*Logger) HealthCheck

func (l *Logger) HealthCheck() error

HealthCheck performs a health check on the logger

func (*Logger) Info

func (l *Logger) Info(message string, fields ...interfaces.LogField)

Info logs an info message

func (*Logger) Rotate

func (l *Logger) Rotate() error

Rotate rotates the log file (if using file output)

func (*Logger) SetLevel

func (l *Logger) SetLevel(level string) error

SetLevel sets the log level

func (*Logger) Warn

func (l *Logger) Warn(message string, fields ...interfaces.LogField)

Warn logs a warning message

func (*Logger) WithContext

func (l *Logger) WithContext(ctx context.Context) interfaces.Logger

WithContext returns a logger with context information

func (*Logger) WithFields

func (l *Logger) WithFields(fields ...interfaces.LogField) interfaces.Logger

WithFields returns a logger with additional fields

type Output

type Output string

Output represents log output destinations

const (
	OutputStdout Output = "stdout"
	OutputStderr Output = "stderr"
	OutputFile   Output = "file"
)

type StructuredLogger

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

StructuredLogger provides additional structured logging capabilities

func NewStructuredLogger

func NewStructuredLogger(cfg *config.LoggingConfig, component, version string) (*StructuredLogger, error)

NewStructuredLogger creates a new structured logger with component information

func (*StructuredLogger) LogCacheOperation

func (sl *StructuredLogger) LogCacheOperation(ctx context.Context, operation, key string, hit bool, duration time.Duration, fields ...interfaces.LogField)

LogCacheOperation logs a cache operation

func (*StructuredLogger) LogDatabaseOperation

func (sl *StructuredLogger) LogDatabaseOperation(ctx context.Context, operation, table string, duration time.Duration, err error, fields ...interfaces.LogField)

LogDatabaseOperation logs a database operation

func (*StructuredLogger) LogMLOperation

func (sl *StructuredLogger) LogMLOperation(ctx context.Context, operation string, inputSize int, confidence float64, duration time.Duration, err error, fields ...interfaces.LogField)

LogMLOperation logs a machine learning operation

func (*StructuredLogger) LogPerformanceMetric

func (sl *StructuredLogger) LogPerformanceMetric(ctx context.Context, metricName string, value float64, unit string, fields ...interfaces.LogField)

LogPerformanceMetric logs a performance metric

func (*StructuredLogger) LogRequest

func (sl *StructuredLogger) LogRequest(ctx context.Context, method, path string, statusCode int, duration time.Duration, fields ...interfaces.LogField)

LogRequest logs an HTTP request

func (*StructuredLogger) LogScanOperation

func (sl *StructuredLogger) LogScanOperation(ctx context.Context, packageName, registry string, riskScore float64, duration time.Duration, err error, fields ...interfaces.LogField)

LogScanOperation logs a package scan operation

func (*StructuredLogger) LogSecurityEvent

func (sl *StructuredLogger) LogSecurityEvent(ctx context.Context, eventType, description string, severity string, fields ...interfaces.LogField)

LogSecurityEvent logs a security-related event

func (*StructuredLogger) LogShutdown

func (sl *StructuredLogger) LogShutdown(ctx context.Context, reason string, fields ...interfaces.LogField)

LogShutdown logs application shutdown information

func (*StructuredLogger) LogStartup

func (sl *StructuredLogger) LogStartup(ctx context.Context, fields ...interfaces.LogField)

LogStartup logs application startup information

Jump to

Keyboard shortcuts

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