Documentation
¶
Index ¶
- func WithCorrelationID(ctx context.Context, id string) context.Context
- func WithRequestID(ctx context.Context, id string) context.Context
- func WithSpanID(ctx context.Context, id string) context.Context
- func WithTraceID(ctx context.Context, id string) context.Context
- func WithUserID(ctx context.Context, id string) context.Context
- type ContextKey
- type EncoderType
- type Field
- type Level
- type Logger
- func (l *Logger) Close() error
- func (l *Logger) Debug(msg string, fields ...Field)
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Debugw(msg string, keysAndValues ...interface{})
- func (l *Logger) Error(msg string, fields ...Field)
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Errorw(msg string, keysAndValues ...interface{})
- func (l *Logger) Fatal(msg string, fields ...Field)
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) Fatalw(msg string, keysAndValues ...interface{})
- func (l *Logger) Info(msg string, fields ...Field)
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) Infow(msg string, keysAndValues ...interface{})
- func (l *Logger) Sync() error
- func (l *Logger) Warn(msg string, fields ...Field)
- func (l *Logger) Warnf(format string, args ...interface{})
- func (l *Logger) Warnw(msg string, keysAndValues ...interface{})
- type LoggerOption
- func WithFileProvider(filename string, maxSize, maxBackups, maxAge int, compress bool) LoggerOption
- func WithGCPProvider(projectID, logName string) LoggerOption
- func WithLevel(level Level) LoggerOption
- func WithStdOutProvider(encoderType EncoderType) LoggerOption
- func WithTimeZone(location *time.Location) LoggerOption
- func WithWriterProvider(writer io.Writer, encoderType EncoderType) LoggerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithCorrelationID ¶ added in v1.0.7
WithCorrelationID attaches a correlation identifier to the context so it can later be surfaced in log fields.
func WithRequestID ¶ added in v1.0.7
WithRequestID records a request identifier on the context.
func WithSpanID ¶ added in v1.0.7
WithSpanID records a span identifier on the context.
func WithTraceID ¶ added in v1.0.7
WithTraceID records a trace identifier on the context.
Types ¶
type ContextKey ¶ added in v1.0.7
type ContextKey string
ContextKey describes the keys we store structured values under when enriching a context for downstream logging.
const ( CorrelationIDKey ContextKey = "correlation_id" RequestIDKey ContextKey = "request_id" UserIDKey ContextKey = "user_id" TraceIDKey ContextKey = "trace_id" SpanIDKey ContextKey = "span_id" )
type EncoderType ¶ added in v1.0.3
type EncoderType string
const ( JSONEncoder EncoderType = "json" ConsoleEncoder EncoderType = "console" )
type Field ¶
type Field struct {
Key string
Value interface{}
}
func FieldsFromContext ¶ added in v1.0.7
FieldsFromContext converts known context values into structured logging fields. Missing values are ignored, allowing the result to be appended directly to a log call: logger.Info("...", FieldsFromContext(ctx)...).
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func NewLogger ¶
func NewLogger(options ...LoggerOption) (*Logger, error)
NewLogger builds a logger from the supplied functional options.
func (*Logger) Close ¶ added in v1.0.4
Close flushes the zap logger and shuts down any provider resources.
type LoggerOption ¶
type LoggerOption func(*loggerConfig)
func WithFileProvider ¶
func WithFileProvider(filename string, maxSize, maxBackups, maxAge int, compress bool) LoggerOption
-------------------------------------------------------------- WithFileProvider – registers a *fileProvider* (pointer) so the instance created here is the one whose internal lumberjack logger can later be closed. Using a pointer ensures that the state mutated in newCore (the stored *lumberjack.Logger*) is retained.
--------------------------------------------------------------
func WithGCPProvider ¶
func WithGCPProvider(projectID, logName string) LoggerOption
WithGCPProvider adds Google Cloud Logging as a destination.
func WithLevel ¶
func WithLevel(level Level) LoggerOption
WithLevel overrides the default log level (Info).
func WithStdOutProvider ¶
func WithStdOutProvider(encoderType EncoderType) LoggerOption
WithStdOutProvider adds a stdout destination.
func WithTimeZone ¶ added in v1.0.8
func WithTimeZone(location *time.Location) LoggerOption
WithTimeZone sets the timezone for the human-readable datetime field. If not specified, defaults to the system's local timezone.
func WithWriterProvider ¶ added in v1.0.3
func WithWriterProvider(writer io.Writer, encoderType EncoderType) LoggerOption
WithWriterProvider adds a custom io.Writer destination.