Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(msg string)
- func Debugf(format string, args ...interface{})
- func Error(msg string)
- func Errorf(format string, args ...interface{})
- func Fatal(msg string)
- func Fatalf(format string, args ...interface{})
- func Info(msg string)
- func Infof(format string, args ...interface{})
- func Panic(msg string)
- func Panicf(format string, args ...interface{})
- func SetFormat(format string)
- func SetLevel(level Level)
- func SetOutput(output io.Writer)
- func Trace(msg string)
- func Tracef(format string, args ...interface{})
- func Warn(msg string)
- func Warnf(format string, args ...interface{})
- type CsmLog
- func (l *CsmLog) Debug(msg string)
- func (l *CsmLog) Debugf(format string, args ...interface{})
- func (l *CsmLog) Error(msg string)
- func (l *CsmLog) Errorf(format string, args ...interface{})
- func (l *CsmLog) Fatal(msg string)
- func (l *CsmLog) Fatalf(format string, args ...interface{})
- func (l *CsmLog) GetLevel() Level
- func (l *CsmLog) Info(msg string)
- func (l *CsmLog) Infof(format string, args ...interface{})
- func (l *CsmLog) Panic(msg string)
- func (l *CsmLog) Panicf(format string, args ...interface{})
- func (l *CsmLog) SetFormat(format string)
- func (l *CsmLog) SetLevel(level Level)
- func (l *CsmLog) SetOutput(output io.Writer)
- func (l *CsmLog) Trace(msg string)
- func (l *CsmLog) Tracef(format string, args ...interface{})
- func (l *CsmLog) TrackDuration(start time.Time) *CsmLog
- func (l *CsmLog) Warn(msg string)
- func (l *CsmLog) Warnf(format string, args ...interface{})
- func (l *CsmLog) WithComponent(name string) *CsmLog
- func (l *CsmLog) WithContext(ctx context.Context) *CsmLog
- func (l *CsmLog) WithFields(fields Fields) *CsmLog
- func (l *CsmLog) WithOperation(name string) *CsmLog
- type Fields
- type Level
Constants ¶
const ( // Key for request id in context RequestIDKey = "csi.requestid" // field for RequestID to be logged RequestIDField = "ReqID" )
const ( // Standard structured log field keys FieldComponent = "component" FieldOperation = "operation" FieldProtocol = "protocol" FieldArrayID = "array_id" FieldVolumeID = "volume_id" FieldVolumeName = "volume_name" FieldNodeID = "node_id" FieldDurationMs = "duration_ms" FieldError = "error" FieldStagingPath = "staging_path" FieldTargetPath = "target_path" FieldDevicePath = "device_path" // Environment variable keys EnvLogFormat = "CSM_LOG_FORMAT" EnvLogLevel = "CSM_LOG_LEVEL" )
Variables ¶
var AllLevels = []Level{ PanicLevel, FatalLevel, ErrorLevel, WarnLevel, InfoLevel, DebugLevel, TraceLevel, }
A constant exposing all logging levels
Functions ¶
Types ¶
type CsmLog ¶
type CsmLog struct {
// contains filtered or unexported fields
}
CsmLog is a structured logger backed by zap that provides timestamp, automatic request ID extraction, and custom formatting standardized across the Container Storage Modules solution.
func New ¶
New creates a new CsmLog instance with the specified configuration. Parameters:
- format: Output format, "json" or "text". If empty, defaults to "text".
- level: Log level. If empty, defaults to InfoLevel.
- output: io.Writer for log output. If nil, defaults to os.Stderr.
Returns a new CsmLog instance that can be configured independently.
func WithContext ¶
func WithFields ¶
func (*CsmLog) TrackDuration ¶
TrackDuration returns a CsmLog with FieldDurationMs computed from the given start time.
func (*CsmLog) WithComponent ¶
WithComponent returns a CsmLog with the FieldComponent pre-set.
func (*CsmLog) WithFields ¶
func (*CsmLog) WithOperation ¶
WithOperation returns a CsmLog with the FieldOperation pre-set.
type Fields ¶
type Fields = map[string]interface{}
func ExtractFieldsFromContext ¶
ExtractFieldsFromContext extracts log fields and request IDs from the context.
type Level ¶
type Level uint32
Level type — same iota values as before for backward compatibility
const ( // PanicLevel level, highest level of severity. Logs and then calls panic with the // message passed to Debug, Info, ... PanicLevel Level = iota // FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the // logging level is set to Panic. FatalLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. ErrorLevel // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel // InfoLevel level. General operational entries about what's going on inside the // application. InfoLevel // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel // TraceLevel level. Designates finer-grained informational events than the Debug. TraceLevel )