Documentation ¶
Index ¶
- Variables
- func Any(key string, value interface{}) zapcore.Field
- func Array(key string, val zapcore.ArrayMarshaler) zapcore.Field
- func Binary(key string, val []byte) zapcore.Field
- func Bool(key string, val bool) zapcore.Field
- func Bools(key string, bs []bool) zapcore.Field
- func ByteString(key string, val []byte) zapcore.Field
- func ByteStrings(key string, bss [][]byte) zapcore.Field
- func Complex128(key string, val complex128) zapcore.Field
- func Complex128s(key string, nums []complex128) zapcore.Field
- func Complex64(key string, val complex64) zapcore.Field
- func Complex64s(key string, nums []complex64) zapcore.Field
- func Duration(key string, val time.Duration) zapcore.Field
- func Durations(key string, ds []time.Duration) zapcore.Field
- func Error(err error) zapcore.Field
- func Errors(key string, errs []error) zapcore.Field
- func Float32(key string, val float32) zapcore.Field
- func Float32s(key string, nums []float32) zapcore.Field
- func Float64(key string, val float64) zapcore.Field
- func Float64s(key string, nums []float64) zapcore.Field
- func InitLogger() error
- func Int(key string, val int) zapcore.Field
- func Int16(key string, val int16) zapcore.Field
- func Int16s(key string, nums []int16) zapcore.Field
- func Int32(key string, val int32) zapcore.Field
- func Int32s(key string, nums []int32) zapcore.Field
- func Int64(key string, val int64) zapcore.Field
- func Int64s(key string, nums []int64) zapcore.Field
- func Int8(key string, val int8) zapcore.Field
- func Int8s(key string, nums []int8) zapcore.Field
- func Ints(key string, nums []int) zapcore.Field
- func NamedError(key string, err error) zapcore.Field
- func Namespace(key string) zapcore.Field
- func Object(key string, val zapcore.ObjectMarshaler) zapcore.Field
- func Reflect(key string, val interface{}) zapcore.Field
- func Skip() zapcore.Field
- func Stack(key string) zapcore.Field
- func String(key string, val string) zapcore.Field
- func Stringer(key string, val fmt.Stringer) zapcore.Field
- func Strings(key string, ss []string) zapcore.Field
- func Time(key string, val time.Time) zapcore.Field
- func Times(key string, ts []time.Time) zapcore.Field
- func Uint(key string, val uint) zapcore.Field
- func Uint16(key string, val uint16) zapcore.Field
- func Uint16s(key string, nums []uint16) zapcore.Field
- func Uint32(key string, val uint32) zapcore.Field
- func Uint32s(key string, nums []uint32) zapcore.Field
- func Uint64(key string, val uint64) zapcore.Field
- func Uint64s(key string, nums []uint64) zapcore.Field
- func Uint8(key string, val uint8) zapcore.Field
- func Uint8s(key string, nums []uint8) zapcore.Field
- func Uintptr(key string, val uintptr) zapcore.Field
- func Uintptrs(key string, us []uintptr) zapcore.Field
- func Uints(key string, us []uint) zapcore.Field
- type Config
- type EnvConfig
- type GelfCore
- func (gc GelfCore) Check(entry zapcore.Entry, checkedEntry *zapcore.CheckedEntry) *zapcore.CheckedEntry
- func (gc GelfCore) Enabled(level zapcore.Level) bool
- func (gc GelfCore) Sync() error
- func (gc GelfCore) With(fields []zapcore.Field) zapcore.Core
- func (gc GelfCore) Write(entry zapcore.Entry, fields []zapcore.Field) error
- type Graylog
- type GraylogConstructor
- type LevedLogger
- type MockEnvConfig
- type MockGraylog
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Logger = getLogger()
Logger is the global logger for the application. Upon first initalization of the logger all calls to 'getLogger' are memoized with the instantiated 'logger'.
Functions ¶
func Any ¶
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) zapcore.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 ¶
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 ByteString ¶
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 ¶
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) zapcore.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) zapcore.Field
Complex128s constructs a field that carries a slice of complex numbers.
func Complex64 ¶
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 ¶
Complex64s constructs a field that carries a slice of complex numbers.
func Duration ¶
Duration constructs a field with the given key and value. The encoder controls how the duration is serialized.
func Float32 ¶
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 Float64 ¶
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 InitLogger ¶ added in v1.1.1
func InitLogger() error
InitLogger initializes a global Logger based upon your env configurations.
Example ¶
if err := InitLogger(); err != nil { panic(err) } defer Logger.Sync() Logger.Info("this is a test info log")
Output:
func NamedError ¶
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 ¶
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) zapcore.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 ¶
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 ¶
Skip constructs a no-op field, which is often useful when handling invalid inputs in other Field constructors.
func Stack ¶
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 Stringer ¶
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 Time ¶
Time constructs a zapcore.Field with the given key and value. The encoder controls how the time is serialized.
Types ¶
type Config ¶
type Config interface {
// contains filtered or unexported methods
}
Config is an interface representing all the logging configurations accessible via environment
type EnvConfig ¶ added in v1.1.1
type EnvConfig struct{}
EnvConfig represents all the logger configurations available when instaniating a new Logger.
type GelfCore ¶
type GelfCore struct { Graylog Graylog Context []zapcore.Field // contains filtered or unexported fields }
GelfCore implements the https://godoc.org/go.uber.org/zap/zapcore#Core interface Messages are written to a graylog endpoint using the GELF format + protocol
func NewGelfCore ¶
NewGelfCore creates a new GelfCore with empty context.
func (GelfCore) Check ¶
func (gc GelfCore) Check(entry zapcore.Entry, checkedEntry *zapcore.CheckedEntry) *zapcore.CheckedEntry
Check determines whether the supplied entry should be logged.
type Graylog ¶
Graylog is a unifying interface for using the internal Graylog package 'github.com/Devatoria/go-graylog', while also being able to use Mocks in it's place.
func NewGraylog ¶
NewGraylog returns a new Graylog instance.
type GraylogConstructor ¶ added in v1.1.1
type LevedLogger ¶ added in v1.1.1
LevedLogger is a unifying type for all of the exported zap leveled loggers, Info, Warn, Error, Debug.
type MockEnvConfig ¶ added in v1.1.1
MockEnvConfig represents all the logger configurations available when instaniating a new Logger via a mock.
type MockGraylog ¶
MockGraylog is a mock Graylog struct used for testing.
func NewMockGraylog ¶
func NewMockGraylog() MockGraylog
NewMockGraylog returns a new MockGraylog struct.
func (*MockGraylog) Close ¶
func (m *MockGraylog) Close() error
Close closes the opened connections of the given client