Documentation
¶
Overview ¶
Package interfaces defines the interfaces for the logging package.
This package provides abstractions for logging functionality that can be implemented by different logging backends. It defines the core Logger interface that all logger implementations must satisfy, enabling dependency inversion and making it easier to swap logging implementations.
The primary interface defined in this package is:
- Logger: A context-aware logging interface that provides methods for logging at different levels (Debug, Info, Warn, Error, Fatal) with context information.
This package is designed to be used in conjunction with the parent logging package, which provides concrete implementations of these interfaces. By depending on these interfaces rather than concrete implementations, application code can remain decoupled from specific logging backends.
Example usage:
// Function that depends on the Logger interface
func ProcessData(ctx context.Context, logger interfaces.Logger, data []byte) error {
logger.Info(ctx, "Processing data", zap.Int("bytes", len(data)))
// Process data...
if err := validateData(data); err != nil {
logger.Error(ctx, "Data validation failed", zap.Error(err))
return err
}
logger.Debug(ctx, "Data processed successfully")
return nil
}
By using the interfaces defined in this package, application code can be tested more easily with mock implementations and can adapt to different logging backends without requiring changes to the code that uses the logger.
Package interfaces defines the interfaces for the logging package. It provides abstractions for logging functionality that can be implemented by different logging backends.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger interface {
// Debug logs a debug-level message with context information
Debug(ctx context.Context, msg string, fields ...zap.Field)
// Info logs an info-level message with context information
Info(ctx context.Context, msg string, fields ...zap.Field)
// Warn logs a warning-level message with context information
Warn(ctx context.Context, msg string, fields ...zap.Field)
// Error logs an error-level message with context information
Error(ctx context.Context, msg string, fields ...zap.Field)
// Fatal logs a fatal-level message with context information
Fatal(ctx context.Context, msg string, fields ...zap.Field)
// Sync flushes any buffered log entries
Sync() error
}
Logger defines the interface for context-aware logging