zapfancyencoder

package module
v0.0.0-...-43cec98 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 7 Imported by: 0

README

zapfancyencoder

The fancy encoder is a zap encoder that prints the logs in a colored human readable format.

Below an example:

Level      : INFO
Message    : message 1
Timestamp  : 2024-07-30 21:20:37 -03:00
Fields     : 
      ├─ persistent: persisted value
      ├─ id        : 1
      └─ obj       : 
          ├─ prop1: value 1
          └─ prop2: 2
------------------------------------
Level      : WARN
Message    : message 2
Timestamp  : 2024-07-30 21:20:37 -03:00
Fields     : 
      ├─ persistent: persisted value
      ├─ id        : 123
      └─ obj       : 
          ├─ name: John
          ├─ age : 32
          └─ arr : 
              ├─ [0] : a
              ├─ [1] : b
              ├─ [0] : c1
              ├─ [1] : c2
              ├─ [3] : d
              ├─ name: John
              └─ age : 32
------------------------------------
Level      : ERROR
Message    : test error message 2
Timestamp  : 2024-07-30 21:20:37 -03:00
Fields     : 
      ├─ persistent: persisted value
      ├─ id        : 2
      └─ obj       : 
          ├─ name: John 2
          └─ age : 32
------------------------------------
Level      : ERROR
Message    : test error message 3
Timestamp  : 2024-07-30 21:20:37 -03:00
Fields     : 
      ├─ persistent: persisted value
      ├─ id        : 3
      └─ obj       : 
          ├─ name: John 3
          └─ age : 33
------------------------------------
Level      : ERROR
Message    : test error message 4
Timestamp  : 2024-07-30 21:20:37 -03:00
Fields     : 
      ├─ persistent: persisted value
      ├─ id        : 4
      └─ obj       : 
          ├─ name: John 4
          └─ age : 34
------------------------------------

Usage

package main

import (
    _ "github.com/jamillosantos/zapfancyencoder"
	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
)

func main() {
    zapcfg := zap.NewDevelopmentConfig()
    zapcfg.Encoding = "fancy"
    logger, err := zapcfg.Build()
	if err != nil {
		panic(err)
	}
    
    logger.
        With(zap.String("field_1", "value_1")).
        Info("Hello, world!",
            zap.String("id", "123"),
            zap.Object("obj", zapcore.ObjectMarshalerFunc(func(enc zapcore.ObjectEncoder) error {
                enc.AddString("name", "John")
                enc.AddInt("age", 32)
                return nil
            })),
        )
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FancyEncoder

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

func (*FancyEncoder) AddArray

func (f *FancyEncoder) AddArray(key string, marshaler zapcore.ArrayMarshaler) error

func (*FancyEncoder) AddBinary

func (f *FancyEncoder) AddBinary(key string, value []byte)

func (*FancyEncoder) AddBool

func (f *FancyEncoder) AddBool(key string, value bool)

func (*FancyEncoder) AddByteString

func (f *FancyEncoder) AddByteString(key string, value []byte)

func (*FancyEncoder) AddComplex128

func (f *FancyEncoder) AddComplex128(key string, value complex128)

func (*FancyEncoder) AddComplex64

func (f *FancyEncoder) AddComplex64(key string, value complex64)

func (*FancyEncoder) AddDuration

func (f *FancyEncoder) AddDuration(key string, value time.Duration)

func (*FancyEncoder) AddFloat32

func (f *FancyEncoder) AddFloat32(key string, value float32)

func (*FancyEncoder) AddFloat64

func (f *FancyEncoder) AddFloat64(key string, value float64)

func (*FancyEncoder) AddInt

func (f *FancyEncoder) AddInt(key string, value int)

func (*FancyEncoder) AddInt16

func (f *FancyEncoder) AddInt16(key string, value int16)

func (*FancyEncoder) AddInt32

func (f *FancyEncoder) AddInt32(key string, value int32)

func (*FancyEncoder) AddInt64

func (f *FancyEncoder) AddInt64(key string, value int64)

func (*FancyEncoder) AddInt8

func (f *FancyEncoder) AddInt8(key string, value int8)

func (*FancyEncoder) AddObject

func (f *FancyEncoder) AddObject(key string, marshaler zapcore.ObjectMarshaler) error

func (*FancyEncoder) AddReflected

func (f *FancyEncoder) AddReflected(key string, value interface{}) error

func (*FancyEncoder) AddString

func (f *FancyEncoder) AddString(key, value string)

func (*FancyEncoder) AddTime

func (f *FancyEncoder) AddTime(key string, value time.Time)

func (*FancyEncoder) AddUint

func (f *FancyEncoder) AddUint(key string, value uint)

func (*FancyEncoder) AddUint16

func (f *FancyEncoder) AddUint16(key string, value uint16)

func (*FancyEncoder) AddUint32

func (f *FancyEncoder) AddUint32(key string, value uint32)

func (*FancyEncoder) AddUint64

func (f *FancyEncoder) AddUint64(key string, value uint64)

func (*FancyEncoder) AddUint8

func (f *FancyEncoder) AddUint8(key string, value uint8)

func (*FancyEncoder) AddUintptr

func (f *FancyEncoder) AddUintptr(key string, value uintptr)

func (*FancyEncoder) AppendArray

func (f *FancyEncoder) AppendArray(marshaler zapcore.ArrayMarshaler) error

func (*FancyEncoder) AppendBool

func (f *FancyEncoder) AppendBool(b bool)

func (*FancyEncoder) AppendByteString

func (f *FancyEncoder) AppendByteString(bytes []byte)

func (*FancyEncoder) AppendComplex128

func (f *FancyEncoder) AppendComplex128(c complex128)

func (*FancyEncoder) AppendComplex64

func (f *FancyEncoder) AppendComplex64(c complex64)

func (*FancyEncoder) AppendDuration

func (f *FancyEncoder) AppendDuration(duration time.Duration)

func (*FancyEncoder) AppendFloat32

func (f *FancyEncoder) AppendFloat32(f2 float32)

func (*FancyEncoder) AppendFloat64

func (f *FancyEncoder) AppendFloat64(f2 float64)

func (*FancyEncoder) AppendInt

func (f *FancyEncoder) AppendInt(i int)

func (*FancyEncoder) AppendInt16

func (f *FancyEncoder) AppendInt16(i int16)

func (*FancyEncoder) AppendInt32

func (f *FancyEncoder) AppendInt32(i int32)

func (*FancyEncoder) AppendInt64

func (f *FancyEncoder) AppendInt64(i int64)

func (*FancyEncoder) AppendInt8

func (f *FancyEncoder) AppendInt8(i int8)

func (*FancyEncoder) AppendObject

func (f *FancyEncoder) AppendObject(marshaler zapcore.ObjectMarshaler) error

func (*FancyEncoder) AppendReflected

func (f *FancyEncoder) AppendReflected(value interface{}) error

func (*FancyEncoder) AppendString

func (f *FancyEncoder) AppendString(s string)

func (*FancyEncoder) AppendTime

func (f *FancyEncoder) AppendTime(t time.Time)

func (*FancyEncoder) AppendUint

func (f *FancyEncoder) AppendUint(u uint)

func (*FancyEncoder) AppendUint16

func (f *FancyEncoder) AppendUint16(u uint16)

func (*FancyEncoder) AppendUint32

func (f *FancyEncoder) AppendUint32(u uint32)

func (*FancyEncoder) AppendUint64

func (f *FancyEncoder) AppendUint64(u uint64)

func (*FancyEncoder) AppendUint8

func (f *FancyEncoder) AppendUint8(u uint8)

func (*FancyEncoder) AppendUintptr

func (f *FancyEncoder) AppendUintptr(u uintptr)

func (*FancyEncoder) Clone

func (f *FancyEncoder) Clone() zapcore.Encoder

func (*FancyEncoder) EncodeEntry

func (f *FancyEncoder) EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)

func (*FancyEncoder) Free

func (f *FancyEncoder) Free()

Free ... TODO Not being cleaned up. Ignoring this for now as this is a PoC.

func (*FancyEncoder) OpenNamespace

func (f *FancyEncoder) OpenNamespace(_ string)

Jump to

Keyboard shortcuts

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