Documentation ¶
Index ¶
- Constants
- func ExtractRequestValuesFromContext(ctx context.Context) []interface{}
- type ContextualLogger
- type Logger
- type NoOpContextualLogger
- func (n NoOpContextualLogger) Debug(ctx context.Context, msg string, keyvals ...interface{})
- func (n NoOpContextualLogger) Error(ctx context.Context, msg string, keyvals ...interface{})
- func (n NoOpContextualLogger) Info(ctx context.Context, msg string, keyvals ...interface{})
- func (n NoOpContextualLogger) Warn(ctx context.Context, msg string, keyvals ...interface{})
- func (n NoOpContextualLogger) With(keyvals ...interface{}) ContextualLogger
- type NoOpLogger
- func (n NoOpLogger) Debug(msg string, keyvals ...interface{})
- func (n NoOpLogger) Error(msg string, keyvals ...interface{})
- func (n NoOpLogger) Info(msg string, keyvals ...interface{})
- func (n NoOpLogger) Warn(msg string, keyvals ...interface{})
- func (n NoOpLogger) With(keyvals ...interface{}) Logger
- type StructuredLogger
- func (s StructuredLogger) Debug(msg string, keyvals ...interface{})
- func (s StructuredLogger) Error(msg string, keyvals ...interface{})
- func (s StructuredLogger) Info(msg string, keyvals ...interface{})
- func (s StructuredLogger) Sugar() zap.SugaredLogger
- func (s StructuredLogger) Warn(msg string, keyvals ...interface{})
- func (s StructuredLogger) With(keyvals ...interface{}) Logger
Constants ¶
const RequestIDKey contextKey = "requestID"
RequestIDKey is the key we associate with the requestID that we set in the request context
Variables ¶
This section is empty.
Functions ¶
func ExtractRequestValuesFromContext ¶
ExtractRequestValuesFromContext extracts request values from a context and returns them as a slice of strings
Types ¶
type ContextualLogger ¶
type ContextualLogger interface { // Info logs a message at the info leve with some additional context via the // passed key value pairs. It also extracts values from the context and logs // them out. Key values and values extracted from the context are treated // as they are in With. Info(ctx context.Context, msg string, keyvals ...interface{}) // Debug logs a message at the debug level with some additional context via // the passed key value pairs. It also extracts values from the context and // logs them out. Key values and values extracted from the context are treated // as they are in With. Debug(ctx context.Context, msg string, keyvals ...interface{}) // Error logs a message at the error level with some additional context via the // passed key value pairs. It also extracts values from the context and logs // them out. Key values and values extracted from the context are treated // as they are in With. Error(ctx context.Context, msg string, keyvals ...interface{}) // Warn logs a message at the warning level with some additional context via the // passed key value pairs. It also extracts values from the context and logs // them out. Key values and values extracted from the context are treated // as they are in With. Warn(ctx context.Context, msg string, keyvals ...interface{}) // With adds fields of key value pairs to the logging context. When processing // pairs the first element is used as the key and the second as the value. With(keyvals ...interface{}) ContextualLogger }
ContextualLogger defines a logger that can extract and log values from a context as well as logging a message and keyvals. When using the logger calls to its methods should include a brief message describing what happened and then key value pairs that contain additional info e.g.
logger.Error(ctx, "failed to retrieve data from DB", "user_id", "1234")
func NewContextualLogger ¶
func NewContextualLogger(logger Logger, extractFn func(context.Context) []interface{}) ContextualLogger
NewContextualLogger creates a contextual logger
type Logger ¶
type Logger interface { // Info logs a message at the info leve with some additional context via the // passed key value pairs. It also extracts values from the context and logs // them out. Info(msg string, keyvals ...interface{}) // Debug logs a message at the debug level with some additional context via // the passed key value pairs. It also extracts values from the context and // logs them out. Debug(msg string, keyvals ...interface{}) // Error logs a message at the error level with some additional context via the // passed key value pairs. It also extracts values from the context and logs // them out. Error(msg string, keyvals ...interface{}) // Warn logs a message at the warning level with some additional context via the // passed key value pairs. It also extracts values from the context and logs // them out. Warn(msg string, keyvals ...interface{}) // With adds fields of key value pairs to the logging context. When processing // pairs the first element is used as the key and the second as the value. With(keyvals ...interface{}) Logger }
Logger defines a logger with multiple logging levels. When using the logger calls to its methods should include a brief message describing what happened and then key value pairs that contain additional info e.g.
logger.Error("failed to retrieve data from DB", "user_id", "1234")
type NoOpContextualLogger ¶
type NoOpContextualLogger struct{}
NoOpContextualLogger is a type that implements the Logger interface but does nothing when it's methods are called
func NewNoOpContextualLogger ¶
func NewNoOpContextualLogger() NoOpContextualLogger
NewNoOpContextualLogger returns a NoOpContextualLogger
func (NoOpContextualLogger) Debug ¶
func (n NoOpContextualLogger) Debug(ctx context.Context, msg string, keyvals ...interface{})
Debug does nothing
func (NoOpContextualLogger) Error ¶
func (n NoOpContextualLogger) Error(ctx context.Context, msg string, keyvals ...interface{})
Error does nothing
func (NoOpContextualLogger) Info ¶
func (n NoOpContextualLogger) Info(ctx context.Context, msg string, keyvals ...interface{})
Info does nothing
func (NoOpContextualLogger) Warn ¶
func (n NoOpContextualLogger) Warn(ctx context.Context, msg string, keyvals ...interface{})
Warn does nothing on a NoOpLogger
func (NoOpContextualLogger) With ¶
func (n NoOpContextualLogger) With(keyvals ...interface{}) ContextualLogger
With does nothing on a NoOpLogger
type NoOpLogger ¶
type NoOpLogger struct{}
NoOpLogger is a type that implements the Logger interface but does nothing when it's methods are called
func (NoOpLogger) Debug ¶
func (n NoOpLogger) Debug(msg string, keyvals ...interface{})
Debug does nothing on a NoOpLogger
func (NoOpLogger) Error ¶
func (n NoOpLogger) Error(msg string, keyvals ...interface{})
Error does nothing on a NoOpLogger
func (NoOpLogger) Info ¶
func (n NoOpLogger) Info(msg string, keyvals ...interface{})
Info does nothing on a NoOpLogger
func (NoOpLogger) Warn ¶
func (n NoOpLogger) Warn(msg string, keyvals ...interface{})
Warn does nothing on a NoOpLogger
func (NoOpLogger) With ¶
func (n NoOpLogger) With(keyvals ...interface{}) Logger
With does nothing on a NoOpLogger
type StructuredLogger ¶
type StructuredLogger struct {
// contains filtered or unexported fields
}
StructuredLogger implements the Logger interface
func NewStructuredLogger ¶
func NewStructuredLogger(level string) (StructuredLogger, error)
NewStructuredLogger creates a StructuredLogger
func NewStructuredLoggerFromSugar ¶
func NewStructuredLoggerFromSugar(s zap.SugaredLogger) StructuredLogger
NewStructuredLoggerFromSugar creates a StrucutredLogger from a Sugared Zap Logger
func (StructuredLogger) Debug ¶
func (s StructuredLogger) Debug(msg string, keyvals ...interface{})
Debug logs a message at the debug level with some additional context via the passed key value pairs. It also extracts values from the context and logs them out. Key values and values extracted from the context are treated as they are in With.
func (StructuredLogger) Error ¶
func (s StructuredLogger) Error(msg string, keyvals ...interface{})
Error logs a message at the error level with some additional context via the passed key value pairs. It also extracts values from the context and logs them out. Key values and values extracted from the context are treated as they are in With.
func (StructuredLogger) Info ¶
func (s StructuredLogger) Info(msg string, keyvals ...interface{})
Info logs a message at the info leve with some additional context via the passed key value pairs. It also extracts values from the context and logs them out. Key values and values extracted from the context are treated as they are in With.
func (StructuredLogger) Sugar ¶
func (s StructuredLogger) Sugar() zap.SugaredLogger
Sugar returns the underlying zap.SugaredLogger that the StructuredLogger uses
func (StructuredLogger) Warn ¶
func (s StructuredLogger) Warn(msg string, keyvals ...interface{})
Warn logs a message at the warning level with some additional context via the passed key value pairs. It also extracts values from the context and logs them out.
func (StructuredLogger) With ¶
func (s StructuredLogger) With(keyvals ...interface{}) Logger
With adds fields of key value pairs to the logging context. When processing pairs the first element is used as the key and the second as the value.