Documentation ¶
Index ¶
- Constants
- Variables
- func Caller(depth int) string
- func Debug(a ...interface{})
- func Debugf(format string, a ...interface{})
- func Error(a ...interface{})
- func Errorf(format string, a ...interface{})
- func Fatal(a ...interface{})
- func Fatalf(format string, a ...interface{})
- func Info(a ...interface{})
- func Infof(format string, a ...interface{})
- func Merge(dst map[string]interface{}, k, v interface{})
- func NewContext(ctx context.Context, l Logger) context.Context
- func TimestampFormat(t time.Time, layout string) string
- func Warn(a ...interface{})
- func Warnf(format string, a ...interface{})
- type Helper
- func (h *Helper) Debug(a ...interface{})
- func (h *Helper) Debugf(format string, a ...interface{})
- func (h *Helper) Debugw(kv ...interface{})
- func (h *Helper) Error(a ...interface{})
- func (h *Helper) Errorf(format string, a ...interface{})
- func (h *Helper) Errorw(kv ...interface{})
- func (h *Helper) Fatal(a ...interface{})
- func (h *Helper) Fatalf(format string, a ...interface{})
- func (h *Helper) Fatalw(kv ...interface{})
- func (h *Helper) Info(a ...interface{})
- func (h *Helper) Infof(format string, a ...interface{})
- func (h *Helper) Infow(kv ...interface{})
- func (h *Helper) WithError(err error) *Helper
- func (h *Helper) WithFields(fields map[string]interface{}) *Helper
- type Level
- type Logger
- type Option
- type Options
Constants ¶
const LevelKey = "level"
LevelKey is logger level key.
Variables ¶
var ( // DefaultTimestamp is a Valuer that returns the current wallclock time, // respecting time zones, when bound. DefaultTimestamp = TimestampFormat(time.Now(), time.RFC3339Nano) // DefaultTimestampUTC is a Valuer that returns the current time in UTC // when bound. DefaultTimestampUTC = TimestampFormat(time.Now().UTC(), time.RFC3339Nano) // DefaultCaller is a Valuer that returns the file and line where the Log // method was invoked. It can only be used with log.With. DefaultCaller = Caller(2) )
var ( // DefaultLogger is default logger. DefaultLogger = NewLogger() )
var ErrMissingValue = errors.New("(MISSING)")
ErrMissingValue is appended to keyvals slices with odd length to substitute the missing value.
Functions ¶
func Caller ¶
Caller returns a Valuer that returns a file and line from a specified depth in the callstack. Users will probably want to use DefaultCaller.
func TimestampFormat ¶
TimestampFormat returns a timestamp Valuer with a custom time format. It invokes the t function to get the time to format; unless you are doing something tricky, pass time.Now. The layout string is passed to Time.Format.
Most users will want to use DefaultTimestamp or DefaultTimestampUTC, which are TimestampFormats that use the RFC3339Nano format.
Types ¶
type Helper ¶
type Helper struct { Logger // contains filtered or unexported fields }
func (*Helper) WithFields ¶
type Level ¶
type Level int8
Level is a logger level.
func ParseLevel ¶
ParseLevel parses a level string into a logger Level value.
type Logger ¶
type Logger interface { // Log writes a log entry Log(level Level, kvs ...interface{}) // Fields set fields to always be logged Fields(fields map[string]interface{}) Logger }
Logger is a logger interface.
func FromContext ¶
func NewJSONLogger ¶
NewJSONLogger returns a Logger that encodes key and val to the Writer as a single JSON object. Each log event produces no more than one call to w.Write. The passed Writer must be safe for concurrent use by multiple goroutines if the returned Logger will be used concurrently.
type Option ¶
type Option func(*Options)
func WithCallerSkipCount ¶
WithCallerSkipCount set frame count to skip
func WithOutput ¶
WithOutput set default output writer for the logger
type Options ¶
type Options struct { // The logging level the logger should log at. default is `InfoLevel` Level Level // fields to always be logged Fields map[string]interface{} // It's common to set this to a file, or leave it default which is `os.Stderr` Out io.Writer // Caller skip frame count for file:line info CallerSkipCount int // Alternative options Context ctx.Context }