Documentation ¶
Index ¶
- Constants
- func GetName(ctx context.Context) (string, bool)
- func GetTraceparent(ctx context.Context) (*tracing.Traceparent, bool)
- func NewContext(ctx context.Context, logger *Logger) context.Context
- func NewTraceparent() (*tracing.Traceparent, error)
- func Tracing(headerName string) func(next http.Handler) http.Handler
- func WithName(ctx context.Context, name string) context.Context
- func WithTraceparent(ctx context.Context, tp *tracing.Traceparent) context.Context
- type Level
- type Logger
- func (l *Logger) Clone(opts ...zap.Option) *Logger
- func (l *Logger) Debug(msg string, fields ...zap.Field)
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Error(msg string, fields ...zap.Field)
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Fatal(msg string, fields ...zap.Field)
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) Info(msg string, fields ...zap.Field)
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) LogRequests() bool
- func (l *Logger) LogResponses() bool
- func (l *Logger) Name() string
- func (l *Logger) StdLogger(level Level) *log.Logger
- func (l *Logger) Sync() error
- func (l *Logger) TimeFormat() string
- func (l *Logger) TraceHeader() string
- func (l *Logger) Warn(msg string, fields ...zap.Field)
- func (l *Logger) Warnf(format string, args ...interface{})
- func (l *Logger) Writer(level Level) io.Writer
- type Option
- func WithCallerSkip(skip int) Option
- func WithConfig(raw json.RawMessage) Option
- func WithFormatJSON() Option
- func WithFormatText() Option
- func WithLogLevel(level Level) Option
- func WithLogRequests() Option
- func WithLogResponses() Option
- func WithTimeFormat(format string) Option
- func WithTraceHeader(name string) Option
Constants ¶
const DefaultTraceHeader = "Traceparent"
DefaultTraceHeader is the default header used as a trace id.
Variables ¶
This section is empty.
Functions ¶
func GetTraceparent ¶ added in v0.0.4
func GetTraceparent(ctx context.Context) (*tracing.Traceparent, bool)
GetTraceparent returns the tracing id from the context if it exists.
func NewContext ¶ added in v0.4.0
NewContext adds the given logger to the context.
func NewTraceparent ¶ added in v0.0.4
func NewTraceparent() (*tracing.Traceparent, error)
NewTraceparent generates a new traceparent.
func Tracing ¶ added in v0.0.4
Tracing returns a new middleware that gets the given header and sets it in the context so it can be written in the logger. If the header does not exists or it's the empty string, it uses github.com/smallstep/tracing to create a new one.
func WithName ¶ added in v0.3.0
WithName returns a new context with the given name in the context. This name will appear in the log entries that include the returning context.
func WithTraceparent ¶ added in v0.0.4
WithTraceparent returns a new context with the given tracing id added to the context.
Types ¶
type Level ¶ added in v0.2.0
type Level int8
Level indicates the log level.
func (Level) MarshalText ¶ added in v0.5.0
MarshalText implements encoding.TextMarshaler for Level.
func (Level) String ¶ added in v0.5.0
String implements fmt.Stringer for Level.
func (*Level) UnmarshalText ¶ added in v0.5.0
UnmarshalText implements encoding.TextUnmarshaler for Level.
type Logger ¶
Logger is a request logger that uses zap.Logger as core.
func FromContext ¶ added in v0.4.0
FromContext returns a logger from the given context.
func (*Logger) Clone ¶ added in v0.0.7
Clone creates a new copy of the logger with the given options.
func (*Logger) Fatal ¶ added in v0.0.8
Fatal logs a message at fatal level and then calls to os.Exit(1).
func (*Logger) Fatalf ¶ added in v0.0.8
Fatalf formats and logs a message at fatal level and then calls to os.Exit(1).
func (*Logger) LogRequests ¶
LogRequests returns if the logging of requests is enabled.
func (*Logger) LogResponses ¶
LogResponses returns if the logging of responses is enabled.
func (*Logger) StdLogger ¶ added in v0.2.0
StdLogger returns a *log.Logger with the specified log level.
func (*Logger) Sync ¶
Sync calls the underlying Core's Sync method, flushing any buffered log entries. Applications should take care to call Sync before exiting.
func (*Logger) TimeFormat ¶
TimeFormat returns the configured time format.
func (*Logger) TraceHeader ¶
TraceHeader returns the trace header configured.
type Option ¶
type Option func(o *options) error
Option is the type used to modify logger options.
func WithCallerSkip ¶ added in v0.0.8
WithCallerSkip increases the number of callers skipped by caller annotation.
func WithConfig ¶
func WithConfig(raw json.RawMessage) Option
WithConfig uses a JSON to configure the logger.
func WithFormatJSON ¶
func WithFormatJSON() Option
WithFormatJSON configures the format of the logs as JSON. Defaults to text.
func WithFormatText ¶
func WithFormatText() Option
WithFormatText configures the format of the logs as text. Defaults to text.
func WithLogLevel ¶ added in v0.5.0
WithLogLevel sets the verbosity of the logger.
func WithLogRequests ¶
func WithLogRequests() Option
WithLogRequests enables the log of the requests.
func WithLogResponses ¶
func WithLogResponses() Option
WithLogResponses enables the log of responses
func WithTimeFormat ¶
WithTimeFormat sets a specific format for the time fields.
func WithTraceHeader ¶
WithTraceHeader defines the name of the header used for tracing. Defaults to 'Traceparent'.