Documentation
¶
Index ¶
- Constants
- func GetTraceparent(ctx context.Context) (*tracing.Traceparent, bool)
- func NewTraceparent() (*tracing.Traceparent, error)
- func Tracing(headerName string) func(next http.Handler) http.Handler
- func WithTraceparent(ctx context.Context, tp *tracing.Traceparent) context.Context
- type CommonLogFormat
- type Logger
- func (l *Logger) Clone(opts ...zap.Option) *Logger
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Errorf(format string, args ...interface{})
- 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) Sync() error
- func (l *Logger) TimeFormat() string
- func (l *Logger) TraceHeader() string
- func (l *Logger) Warnf(format string, args ...interface{})
- type 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)
GetTracing returns the tracing id from the context if it exists.
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 WithTraceparent ¶ added in v0.0.4
WithTraceparent returns a new context with the given tracing id added to the context.
Types ¶
type CommonLogFormat ¶
type CommonLogFormat struct{}
CommonLogFormat implements the logrus.Formatter interface it writes logrus entries using a CLF format prepended by the request-id.
func (*CommonLogFormat) Format ¶
func (f *CommonLogFormat) Format(entry *logrus.Entry) ([]byte, error)
Format implements the logrus.Formatter interface. It returns the given logrus entry as a CLF line with the following format:
<request-id> <remote-address> <name> <user-id> <time> <duration> "<method> <path> <protocol>" <status> <size>
If a field is not known, the hyphen symbol (-) will be used.
type Logger ¶
Logger is a request logger that uses zap.Logger as core.
func (*Logger) Clone ¶ added in v0.0.7
Clones creates a new copy of the logger with the given options.
func (*Logger) LogRequests ¶
LogResponses returns if the logging of requests is enabled.
func (*Logger) LogResponses ¶
LogResponses returns if the logging of responses is enabled.
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 ¶
GetTraceHeader returns the trace header configured.
type Option ¶
type Option func(o *options) error
Options is the type used to modify logger options.
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 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'.