logus

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2019 License: Apache-2.0 Imports: 9 Imported by: 13

README

logus

Just a wrap of Zap, export useful interface.

package main

import "github.com/alimy/logus"

func main() {
    logus.Debug("just a wrap of zap")
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DP added in v0.3.0

func DP(msg string, err error, fields ...Field)

DP logs a message at DPanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

If the logger is in development mode, it then panics (DPanic means "development panic"). This is useful for catching errors that are recoverable, but shouldn't ever happen.

func DPanic

func DPanic(msg string, fields ...Field)

DPanic logs a message at DPanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

If the logger is in development mode, it then panics (DPanic means "development panic"). This is useful for catching errors that are recoverable, but shouldn't ever happen.

Example
defer func() {
	recover()
}()

DPanic("DPanic level message", Time("time", time.Now().Local()))
Output:

func Debug

func Debug(msg string, fields ...Field)

Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

Example
Debug("Debug level message",
	Time("time", time.Now().Local()),
	Ints("Ints", 1, 2),
	Any("Any", []int{1, 2}))
Output:

func E added in v0.3.0

func E(msg string, err error, fields ...Field)

E logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

func Error

func Error(msg string, fields ...Field)

Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

Example
Error("Error level message", Time("time", time.Now().Local()))
Output:

func F added in v0.3.0

func F(msg string, err error, fields ...Field)

F logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.

func Fatal

func Fatal(msg string, fields ...Field)

Fatal logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.

Example
Error("Fatal level message", Time("time", time.Now().Local()))
Output:

func InDevelopment

func InDevelopment(opts ...Option)

InDevelopment is a reasonable development logging configuration. Logging is enabled at DebugLevel and above.

It enables development mode (which makes DPanicLevel logs panic), uses a console encoder, writes to standard error, and disables sampling. StackTraces are automatically included on logs of WarnLevel and above.

func InProduction

func InProduction(opts ...Option)

InProduction is a reasonable production logging configuration. Logging is enabled at InfoLevel and above.

It uses a JSON encoder, writes to standard error, and enables sampling. StackTraces are automatically included on logs of ErrorLevel and above.

func Info

func Info(msg string, fields ...Field)

Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

Example
Info("Info level message", Time("time", time.Now().Local()))
Output:

func Named

func Named(s string)

Named adds a new path segment to the logger's name. Segments are joined by periods. By default, Loggers are unnamed.

func P added in v0.3.0

func P(msg string, err error, fields ...Field)

P logs a message at PanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.

func Panic

func Panic(msg string, fields ...Field)

Panic logs a message at PanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.

Example
defer func() {
	recover()
}()

Panic("Panic level message", Time("time", time.Now().Local()))
Output:

func Sync

func Sync() error

Sync calls the underlying Core's Sync method, flushing any buffered log entries. Applications should take care to call Sync before exiting.

func Warn

func Warn(msg string, fields ...Field)

Warn logs a message at WarnLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

Example
Warn("Warn level message", Time("time", time.Now().Local()))
Output:

func With

func With(fields ...Field)

With creates a child logger and adds structured context to it. Fields added to the child don't affect the parent, and vice versa.

func WithCallerSkip

func WithCallerSkip(skip int)

WithCallerSkip increases the number of callers skipped by caller annotation (as enabled by the AddCaller option).

func WithOptions

func WithOptions(opts ...Option)

WithOptions applies the supplied Options.

Types

type Config

type Config = zap.Config

type Field

type Field = zap.Field

func Any

func Any(key string, value interface{}) Field

Any takes a key and an arbitrary value and chooses the best way to represent them as a field, falling back to a reflection-based approach only if necessary.

Since byte/uint8 and rune/int32 are aliases, Any can't differentiate between them. To minimize surprises, []byte values are treated as binary blobs, byte values are treated as uint8, and runes are always treated as integers.

func Array

func Array(key string, val zapcore.ArrayMarshaler) Field

Array constructs a field with the given key and ArrayMarshaler. It provides a flexible, but still type-safe and efficient, way to add array-like types to the logging context. The struct's MarshalLogArray method is called lazily.

func Binary

func Binary(key string, val []byte) Field

Binary constructs a field that carries an opaque binary blob.

Binary data is serialized in an encoding-appropriate format. For example, zap's JSON encoder base64-encodes binary blobs. To log UTF-8 encoded text, use ByteString.

func Bool

func Bool(key string, val bool) Field

Bool constructs a field that carries a bool.

func Bools

func Bools(key string, bs ...bool) Field

Bools constructs a field that carries a slice of bools.

func ByteString

func ByteString(key string, val []byte) Field

ByteString constructs a field that carries UTF-8 encoded text as a []byte. To log opaque binary blobs (which aren't necessarily valid UTF-8), use Binary.

func ByteStrings

func ByteStrings(key string, bss ...[]byte) Field

ByteStrings constructs a field that carries a slice of []byte, each of which must be UTF-8 encoded text.

func Complex128

func Complex128(key string, val complex128) Field

Complex128 constructs a field that carries a complex number. Unlike most numeric fields, this costs an allocation (to convert the complex128 to interface{}).

func Complex128s

func Complex128s(key string, nums ...complex128) Field

Complex128s constructs a field that carries a slice of complex numbers.

func Complex64

func Complex64(key string, val complex64) Field

Complex64 constructs a field that carries a complex number. Unlike most numeric fields, this costs an allocation (to convert the complex64 to interface{}).

func Complex64s

func Complex64s(key string, nums ...complex64) Field

Complex64s constructs a field that carries a slice of complex numbers.

func Duration

func Duration(key string, val time.Duration) Field

Duration constructs a field with the given key and value. The encoder controls how the duration is serialized.

func Durations

func Durations(key string, ds ...time.Duration) Field

Durations constructs a field that carries a slice of time.Durations.

func ErrorF

func ErrorF(err error) Field

ErrorF is shorthand for the common idiom NamedError("error", err). Deprecated: use ErrorField make more semantic sense.

func ErrorField added in v0.2.2

func ErrorField(err error) Field

ErrorField is shorthand for the common idiom NamedError("error", err).

func Errors

func Errors(key string, errs ...error) Field

Errors constructs a field that carries a slice of errors.

func Float32

func Float32(key string, val float32) Field

Float32 constructs a field that carries a float32. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.

func Float32s

func Float32s(key string, nums ...float32) Field

Float32s constructs a field that carries a slice of floats.

func Float64

func Float64(key string, val float64) Field

Float64 constructs a field that carries a float64. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.

func Float64s

func Float64s(key string, nums ...float64) Field

Float64s constructs a field that carries a slice of floats.

func Int

func Int(key string, val int) Field

Int constructs a field with the given key and value.

func Int16

func Int16(key string, val int16) Field

Int16 constructs a field with the given key and value.

func Int16s

func Int16s(key string, nums ...int16) Field

Int16s constructs a field that carries a slice of integers.

func Int32

func Int32(key string, val int32) Field

Int32 constructs a field with the given key and value.

func Int32s

func Int32s(key string, nums ...int32) Field

Int32s constructs a field that carries a slice of integers.

func Int64

func Int64(key string, val int64) Field

Int64 constructs a field with the given key and value.

func Int64s

func Int64s(key string, nums ...int64) Field

Int64s constructs a field that carries a slice of integers.

func Int8

func Int8(key string, val int8) Field

Int8 constructs a field with the given key and value.

func Int8s

func Int8s(key string, nums ...int8) Field

Int8s constructs a field that carries a slice of integers.

func Ints

func Ints(key string, nums ...int) Field

Ints constructs a field that carries a slice of integers.

func NamedError

func NamedError(key string, err error) Field

NamedError constructs a field that lazily stores err.Error() under the provided key. Errors which also implement fmt.Formatter (like those produced by github.com/pkg/errors) will also have their verbose representation stored under key+"Verbose". If passed a nil error, the field is a no-op.

For the common case in which the key is simply "error", the Error function is shorter and less repetitive.

func Namespace

func Namespace(key string) Field

Namespace creates a named, isolated scope within the logger's context. All subsequent fields will be added to the new namespace.

This helps prevent key collisions when injecting loggers into sub-components or third-party libraries.

func Object

func Object(key string, val zapcore.ObjectMarshaler) Field

Object constructs a field with the given key and ObjectMarshaler. It provides a flexible, but still type-safe and efficient, way to add map- or struct-like user-defined types to the logging context. The struct's MarshalLogObject method is called lazily.

func Reflect

func Reflect(key string, val interface{}) Field

Reflect constructs a field with the given key and an arbitrary object. It uses an encoding-appropriate, reflection-based function to lazily serialize nearly any object into the logging context, but it's relatively slow and allocation-heavy. Outside tests, Any is always a better choice.

If encoding fails (e.g., trying to serialize a map[int]string to JSON), Reflect includes the error message in the final log output.

func Skip

func Skip() Field

Skip constructs a no-op field, which is often useful when handling invalid inputs in other Field constructors.

func Stack

func Stack(key string) Field

Stack constructs a field that stores a stacktrace of the current goroutine under provided key. Keep in mind that taking a stacktrace is eager and expensive (relatively speaking); this function both makes an allocation and takes about two microseconds.

func String

func String(key string, val string) Field

String constructs a field with the given key and value.

func Stringer

func Stringer(key string, val fmt.Stringer) Field

Stringer constructs a field with the given key and the output of the value's String method. The Stringer's String method is called lazily.

func Strings

func Strings(key string, ss ...string) Field

Strings constructs a field that carries a slice of strings.

func Time

func Time(key string, val time.Time) Field

Time constructs a Field with the given key and value. The encoder controls how the time is serialized.

func Times

func Times(key string, ts ...time.Time) Field

Times constructs a field that carries a slice of time.Times.

func Uint

func Uint(key string, val uint) Field

Uint constructs a field with the given key and value.

func Uint16

func Uint16(key string, val uint16) Field

Uint16 constructs a field with the given key and value.

func Uint16s

func Uint16s(key string, nums ...uint16) Field

Uint16s constructs a field that carries a slice of unsigned integers.

func Uint32

func Uint32(key string, val uint32) Field

Uint32 constructs a field with the given key and value.

func Uint32s

func Uint32s(key string, nums ...uint32) Field

Uint32s constructs a field that carries a slice of unsigned integers.

func Uint64

func Uint64(key string, val uint64) Field

Uint64 constructs a field with the given key and value.

func Uint64s

func Uint64s(key string, nums ...uint64) Field

Uint64s constructs a field that carries a slice of unsigned integers.

func Uint8

func Uint8(key string, val uint8) Field

Uint8 constructs a field with the given key and value.

func Uint8s

func Uint8s(key string, nums ...uint8) Field

Uint8s constructs a field that carries a slice of unsigned integers.

func Uintptr

func Uintptr(key string, val uintptr) Field

Uintptr constructs a field with the given key and value.

func Uintptrs

func Uintptrs(key string, us ...uintptr) Field

Uintptrs constructs a field that carries a slice of pointer addresses.

func Uints

func Uints(key string, nums ...uint) Field

Uints constructs a field that carries a slice of unsigned integers.

type Option

type Option = zap.Option

Directories

Path Synopsis
internal
bufferpool
Package bufferpool houses zap's shared internal buffer pool.
Package bufferpool houses zap's shared internal buffer pool.

Jump to

Keyboard shortcuts

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