logger

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2020 License: MIT Imports: 4 Imported by: 0

README

logger

It is simple logger with fields and levels.

It usage js console.log and type safe fo syscall/js.

Example

log := logger.New()

log = log.WithString("key", "value")

log.WithError(nil).Warn("Some warning")

log.Info("Info text")
With types

Go code

log := logger.New()
log.WithInt64("i64", 64).
	WithInt64s("i64s", []int64{1, 3}).
	WithFloat64s("f64s", []float64{1.45, 1}).
	WithInterface("interface", log).
	WithInterfaces("interfaces_wrong", []interface{}{log, 222222}).
	WithInterfaces("interfaces_ok", []interface{}{3, 4, 5}).
	WithStrings("strings", []string{"ddd", "1"}).
	WithError(nil).
	WithErr("not_nil_error", errors.New("some err")).
	Debug("Fields")
	
// Do not use this way. It is very expensive. Use l.WithFields()

JS console

{
	fields: {
		i64: 64
		i64s: Array [ 1, 3 ]
		f64s: Array [ 1.45, 1 ]
		interface: "cannot convert this val in WithInterface method"
		interfaces_wrong: "cannot convert this val in WithInterfaces method"
		interfaces_ok: Array(3) [ 3, 4, 5 ]
		strings: Array [ "ddd", "1" ]
		error: null
		not_nil_error: "some err"
	}
	msg: "Fields"
}
Without types

If you need more fat logger then use enrich wrapper

Go code

log := enrich.New(logger.New())

log.WithField("any_type", log).
	WithField("my_field", 5).
	Debug("Any types fields")

JS console

{
	fields: {
		any_type: "enrich.Logger{log:(*logger.Logger)(0x40e3b0)}"​​
		my_field: 5
	}
	msg: "Any types fields"
}

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

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

Logger main type of the logger

func New

func New() *Logger

New creates New logger with console.log

func (*Logger) Debug

func (l *Logger) Debug(msg string)

Debug prints debug message

func (*Logger) Error

func (l *Logger) Error(msg string)

Error prints error message with stacktrace

func (*Logger) Info

func (l *Logger) Info(msg string)

Info prints info message

func (*Logger) Trace

func (l *Logger) Trace()

Trace prints stacktrace

func (*Logger) Warn

func (l *Logger) Warn(msg string)

Warn prints warning message

func (*Logger) WithBool added in v1.0.1

func (l *Logger) WithBool(key string, val bool) *Logger

WithBool appends bool to field list

func (*Logger) WithErr

func (l *Logger) WithErr(key string, err error) *Logger

WithErr appends error to field list with custom key

func (*Logger) WithError

func (l *Logger) WithError(err error) *Logger

WithError appends error to field list with "error" key

func (*Logger) WithFields added in v1.0.1

func (l *Logger) WithFields(f map[string]interface{}) *Logger

WithFields appends fields set to list use only base types: nil, bool, integers, floats, string

func (*Logger) WithFloat32

func (l *Logger) WithFloat32(key string, val float32) *Logger

WithFloat32 appends float32 to field list

func (*Logger) WithFloat32s

func (l *Logger) WithFloat32s(key string, val []float32) *Logger

WithFloat32s appends []float32 to field list

func (*Logger) WithFloat64

func (l *Logger) WithFloat64(key string, val float64) *Logger

WithFloat64 appends float64 to field list

func (*Logger) WithFloat64s

func (l *Logger) WithFloat64s(key string, val []float64) *Logger

WithFloat64s appends []float64 to field list

func (*Logger) WithInt

func (l *Logger) WithInt(key string, val int) *Logger

WithInt appends int to field list

func (*Logger) WithInt16

func (l *Logger) WithInt16(key string, val int16) *Logger

WithInt16 appends int16 to field list

func (*Logger) WithInt16s

func (l *Logger) WithInt16s(key string, val []int16) *Logger

WithInt16s appends []int16 to field list

func (*Logger) WithInt32

func (l *Logger) WithInt32(key string, val int32) *Logger

WithInt32 appends int32 to field list

func (*Logger) WithInt32s

func (l *Logger) WithInt32s(key string, val []int32) *Logger

WithInt32s appends []int32 to field list

func (*Logger) WithInt64

func (l *Logger) WithInt64(key string, val int64) *Logger

WithInt64 appends int64 to field list

func (*Logger) WithInt64s

func (l *Logger) WithInt64s(key string, val []int64) *Logger

WithInt64s appends []int64 to field list

func (*Logger) WithInt8

func (l *Logger) WithInt8(key string, val int8) *Logger

WithInt8 appends int8 to field list

func (*Logger) WithInt8s

func (l *Logger) WithInt8s(key string, val []int8) *Logger

WithInt8s appends []int8 to field list

func (*Logger) WithInterface

func (l *Logger) WithInterface(key string, val interface{}) *Logger

WithInterface appends interface{} to field list make sure that val contains type of this file only

func (*Logger) WithInterfaces

func (l *Logger) WithInterfaces(key string, val []interface{}) *Logger

WithInterfaces appends []interface{} to field list make sure that slice contains types of this file only

func (*Logger) WithInts

func (l *Logger) WithInts(key string, val []int) *Logger

WithInts appends []int to field list

func (*Logger) WithJSValue

func (l *Logger) WithJSValue(key string, val js.Value) *Logger

WithJSValue appends js.Value to field list

func (*Logger) WithJSWrapper

func (l *Logger) WithJSWrapper(key string, val js.Wrapper) *Logger

WithJSWrapper appends js.Wrapper to field list

func (*Logger) WithObject

func (l *Logger) WithObject(key string, val map[string]interface{}) *Logger

WithObject appends map[string]interface{} to field list make sure that interface contains types of this file only

func (*Logger) WithString

func (l *Logger) WithString(key, val string) *Logger

WithString appends string to field list

func (*Logger) WithStrings

func (l *Logger) WithStrings(key string, val []string) *Logger

WithStrings appends []string to field list

func (*Logger) WithUint

func (l *Logger) WithUint(key string, val uint) *Logger

WithUint appends uint to field list

func (*Logger) WithUint16

func (l *Logger) WithUint16(key string, val uint16) *Logger

WithUint16 appends uint16 to field list

func (*Logger) WithUint16s

func (l *Logger) WithUint16s(key string, val []uint16) *Logger

WithUint16s appends []uint16 to field list

func (*Logger) WithUint32

func (l *Logger) WithUint32(key string, val uint32) *Logger

WithUint32 appends uint32 to field list

func (*Logger) WithUint32s

func (l *Logger) WithUint32s(key string, val []uint32) *Logger

WithUint32s appends []uint32 to field list

func (*Logger) WithUint64

func (l *Logger) WithUint64(key string, val uint64) *Logger

WithUint64 appends uint64 to field list

func (*Logger) WithUint64s

func (l *Logger) WithUint64s(key string, val []uint64) *Logger

WithUint64s appends []uint64 to field list

func (*Logger) WithUint8

func (l *Logger) WithUint8(key string, val uint8) *Logger

WithUint8 appends uint8 to field list

func (*Logger) WithUint8s

func (l *Logger) WithUint8s(key string, val []uint8) *Logger

WithUint8s appends []uint8 to field list

func (*Logger) WithUintptr

func (l *Logger) WithUintptr(key string, val uintptr) *Logger

WithUintptr appends uintptr to field list

func (*Logger) WithUints

func (l *Logger) WithUints(key string, val []uint) *Logger

WithUints appends []uint to field list

func (*Logger) WithUnsafePointer

func (l *Logger) WithUnsafePointer(key string, val unsafe.Pointer) *Logger

WithUnsafePointer appends unsafe.Pointer to field list

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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