log

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Ldate         = 1 << iota     // the date in the local time zone: 2009/01/23
	Ltime                         // the time in the local time zone: 01:23:23
	Lmicroseconds                 // microsecond resolution: 01:23:23.123123.  assumes Ltime.
	Llongfile                     // full file name and line number: /a/b/c/d.go:23
	Lshortfile                    // final file name element and line number: d.go:23. overrides Llongfile
	LUTC                          // if Ldate or Ltime is set, use UTC rather than the local time zone
	LstdFlags     = Ldate | Ltime // initial values for the standard logger
)
View Source
const (
	DEBUG = iota
	INFO
	WARN
	ERROR
	NOLOG
)

Variables

View Source
var (
	LEVEL_NAME map[int]string
	LOG_LEVEL  int
	OPEN_STACK bool
)
View Source
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(
		func() time.Time { return 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(3)
)
View Source
var ErrInvalidKey = errors.New("invalid key")

ErrInvalidKey is returned by Marshal functions and Encoder methods if, after dropping invalid runes, a key is empty.

View Source
var ErrNilKey = errors.New("nil key")

ErrNilKey is returned by Marshal functions and Encoder methods if a key is a nil interface or pointer value.

View Source
var ErrUnsupportedKeyType = errors.New("unsupported key type")

ErrUnsupportedKeyType is returned by Encoder methods if a key has an unsupported type.

View Source
var ErrUnsupportedValueType = errors.New("unsupported value type")

ErrUnsupportedValueType is returned by Encoder methods if a value has an unsupported type.

Functions

func Debug

func Debug(v ...interface{})

func Debugf

func Debugf(format string, v ...interface{})

func Error

func Error(v ...interface{})

func Errorf

func Errorf(format string, v ...interface{})

func Info

func Info(v ...interface{})

func Infof

func Infof(format string, v ...interface{})

func Log

func Log(v ...interface{})

func Logf

func Logf(format string, v ...interface{})

func MarshalKeyvals

func MarshalKeyvals(keyvals ...interface{}) ([]byte, error)

MarshalKeyvals returns the logfmt encoding of keyvals, a variadic sequence of alternating keys and values.

func NewSyncWriter

func NewSyncWriter(w io.Writer) io.Writer

NewSyncWriter returns a new writer that is safe for concurrent use by multiple goroutines. Writes to the returned writer are passed on to w. If another write is already in progress, the calling goroutine blocks until the writer is available.

If w implements the following interface, so does the returned writer.

interface {
    Fd() uintptr
}

func OpenStack

func OpenStack()

func SetFlags

func SetFlags(flag int)

func SetLevel

func SetLevel(level int)

func Warn

func Warn(v ...interface{})

func Warnf

func Warnf(format string, v ...interface{})

Types

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

An Encoder writes logfmt data to an output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) EncodeKeyval

func (enc *Encoder) EncodeKeyval(key, value interface{}, needQuoted bool) error

EncodeKeyval writes the logfmt encoding of key and value to the stream. A single space is written before the second and subsequent keys in a record. Nothing is written if a non-nil error is returned.

func (*Encoder) EncodeKeyvals

func (enc *Encoder) EncodeKeyvals(keyvals ...interface{}) error

EncodeKeyvals writes the logfmt encoding of keyvals to the stream. Keyvals is a variadic sequence of alternating keys and values. Keys of unsupported type are skipped along with their corresponding value. Values of unsupported type or that cause a MarshalerError are replaced by their error but do not cause EncodeKeyvals to return an error. If a non-nil error is returned some key/value pairs may not have be written.

func (*Encoder) EncodeKeyvalsWithQuoted

func (enc *Encoder) EncodeKeyvalsWithQuoted(keyvals ...interface{}) error

func (*Encoder) EndRecord

func (enc *Encoder) EndRecord() error

EndRecord writes a newline character to the stream and resets the encoder to the beginning of a new record.

func (*Encoder) Reset

func (enc *Encoder) Reset()

Reset resets the encoder to the beginning of a new record.

type InfluxdbLogger

type InfluxdbLogger struct {
	// contains filtered or unexported fields
}

func (*InfluxdbLogger) KVLog

func (l *InfluxdbLogger) KVLog(keyvals ...interface{}) error

func (InfluxdbLogger) SetDepth

func (l InfluxdbLogger) SetDepth(depth int) Logger

func (*InfluxdbLogger) SetFlags

func (l *InfluxdbLogger) SetFlags(flag int)

func (*InfluxdbLogger) VLog

func (l *InfluxdbLogger) VLog(v ...interface{}) error

func (InfluxdbLogger) WithHeader

func (l InfluxdbLogger) WithHeader(keyvals ...interface{}) Logger

type Logger

type Logger interface {
	VLog(keyvals ...interface{}) error
	KVLog(keyvals ...interface{}) error
	WithHeader(keyvals ...interface{}) Logger
	SetDepth(depth int) Logger
	SetFlags(flag int)
}

func NewInfluxdbLogger

func NewInfluxdbLogger(w io.Writer, measurement string, kv ...string) Logger

func NewOriginLogger

func NewOriginLogger(w io.Writer) Logger

func WithHeader

func WithHeader(keyvals ...interface{}) Logger

type MarshalerError

type MarshalerError struct {
	Type reflect.Type
	Err  error
}

MarshalerError represents an error encountered while marshaling a value.

func (*MarshalerError) Error

func (e *MarshalerError) Error() string

type OriginLogger

type OriginLogger struct {
	// contains filtered or unexported fields
}

func (*OriginLogger) KVLog

func (this *OriginLogger) KVLog(v ...interface{}) error

func (OriginLogger) SetDepth

func (this OriginLogger) SetDepth(depth int) Logger

func (*OriginLogger) SetFlags

func (this *OriginLogger) SetFlags(flag int)

func (*OriginLogger) VLog

func (this *OriginLogger) VLog(v ...interface{}) error

func (OriginLogger) WithHeader

func (this OriginLogger) WithHeader(keyvals ...interface{}) Logger

type SwapLogger

type SwapLogger struct {
	// contains filtered or unexported fields
}

SwapLogger wraps another logger that may be safely replaced while other goroutines use the SwapLogger concurrently. The zero value for a SwapLogger will discard all log events without error.

SwapLogger serves well as a package global logger that can be changed by importers.

func (*SwapLogger) Log

func (l *SwapLogger) Log(keyvals ...interface{}) error

Log implements the Logger interface by forwarding keyvals to the currently wrapped logger. It does not log anything if the wrapped logger is nil.

func (*SwapLogger) Swap

func (l *SwapLogger) Swap(logger Logger)

Swap replaces the currently wrapped logger with logger. Swap may be called concurrently with calls to Log from other goroutines.

type Valuer

type Valuer func() interface{}

A Valuer generates a log value. When passed to With or WithPrefix in a value element (odd indexes), it represents a dynamic value which is re- evaluated with each log event.

func Caller

func Caller(depth int) Valuer

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 Timestamp

func Timestamp(t func() time.Time) Valuer

Timestamp returns a timestamp Valuer. It invokes the t function to get the time; unless you are doing something tricky, pass time.Now.

Most users will want to use DefaultTimestamp or DefaultTimestampUTC, which are TimestampFormats that use the RFC3339Nano format.

func TimestampFormat

func TimestampFormat(t func() time.Time, layout string) Valuer

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL