Documentation ¶
Index ¶
- Constants
- Variables
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func Error(v ...interface{})
- func Errorf(format string, v ...interface{})
- func Info(v ...interface{})
- func Infof(format string, v ...interface{})
- func Log(v ...interface{})
- func Logf(format string, v ...interface{})
- func MarshalKeyvals(keyvals ...interface{}) ([]byte, error)
- func NewSyncWriter(w io.Writer) io.Writer
- func OpenStack()
- func SetFlags(flag int)
- func SetLevel(level int)
- func Warn(v ...interface{})
- func Warnf(format string, v ...interface{})
- type Encoder
- type InfluxdbLogger
- type Logger
- type MarshalerError
- type OriginLogger
- type SwapLogger
- type Valuer
Constants ¶
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 )
const ( DEBUG = iota INFO WARN ERROR NOLOG )
Variables ¶
var ( LEVEL_NAME map[int]string LOG_LEVEL int OPEN_STACK bool )
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) )
var ErrInvalidKey = errors.New("invalid key")
ErrInvalidKey is returned by Marshal functions and Encoder methods if, after dropping invalid runes, a key is empty.
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.
var ErrUnsupportedKeyType = errors.New("unsupported key type")
ErrUnsupportedKeyType is returned by Encoder methods if a key has an unsupported type.
var ErrUnsupportedValueType = errors.New("unsupported value type")
ErrUnsupportedValueType is returned by Encoder methods if a value has an unsupported type.
Functions ¶
func MarshalKeyvals ¶
MarshalKeyvals returns the logfmt encoding of keyvals, a variadic sequence of alternating keys and values.
func NewSyncWriter ¶
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 }
Types ¶
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder writes logfmt data to an output stream.
func NewEncoder ¶
NewEncoder returns a new encoder that writes to w.
func (*Encoder) EncodeKeyval ¶
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 ¶
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 ¶
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 NewOriginLogger ¶
func WithHeader ¶
func WithHeader(keyvals ...interface{}) Logger
type MarshalerError ¶
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 ¶
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 ¶
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 ¶
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.