logging

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: MIT Imports: 16 Imported by: 0

README

ngr-logging

logging module (logrus inside) TODO:

  • add other logger instances creation
  • add multi-writers logging
  • rewrite formatter logic

import

import "github.com/NGRsoftlab/ngr-logging"

examples

logging.Logger.Trace("trace msg")
logging.Logger.Debug("debug msg") // Debugf, etc.
logging.Logger.Info("info msg") // Infof, etc.
logging.Logger.Warning("warn msg") // Warningf, etc.
logging.Logger.Error("error msg") // Errorf, etc.
logging.Logger.Fatal("fatal msg")
logging.Logger.Panic("panic msg") // do not use panic pls ^^

// also you can import logging like ". "github.com/NGRsoftlab/ngr-logging"" and use Logger.Debug("debug") constructions
// without logging alias

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Log = NewLogger("", "", "", "", "")

Log - Default logger

Functions

This section is empty.

Types

type Context

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

func (Context) Any

func (c Context) Any(key string, i interface{}) Context

Any is a wrapper around Context.Interface.

func (Context) Bool

func (c Context) Bool(key string, b bool) Context

Bool adds the field key with val as a bool to the logger context.

func (Context) Bools

func (c Context) Bools(key string, b []bool) Context

Bools adds the field key with val as a []bool to the logger context.

func (Context) Ctx

func (c Context) Ctx(ctx context.Context) Context

Ctx adds the context.Context to the logger context. The context.Context is not rendered in the error message, but is made available for hooks to use. A typical use case is to extract tracing information from the context.Context.

func (Context) Debug

func (c Context) Debug(args ...interface{})

func (Context) Debugf

func (c Context) Debugf(format string, args ...interface{})

func (Context) Dur added in v2.0.1

func (c Context) Dur(key string, d time.Duration) Context

Dur adds the fields key with d divided by unit and stored as a float.

func (Context) Durs added in v2.0.1

func (c Context) Durs(key string, d []time.Duration) Context

Durs adds the fields key with d divided by unit and stored as a float.

func (Context) Err

func (c Context) Err(err error) Context

Err adds the field "error" with serialized err to the logger context.

func (Context) Error

func (c Context) Error(args ...interface{})

func (Context) Errorf

func (c Context) Errorf(format string, args ...interface{})

func (Context) Errs

func (c Context) Errs(key string, errs []error) Context

Errs adds the field key with errs as an array of serialized errors to the logger context.

func (Context) Fatal

func (c Context) Fatal(args ...interface{})

func (Context) Fatalf

func (c Context) Fatalf(format string, args ...interface{})

func (Context) Fields

func (c Context) Fields(fields interface{}) Context

Fields is a helper function to use a map or slice to set fields using type assertion. Only map[string]interface{} and []interface{} are accepted. []interface{} must alternate string keys and arbitrary values, and extraneous ones are ignored.

func (Context) Float32

func (c Context) Float32(key string, f float32) Context

Float32 adds the field key with f as a float32 to the logger context.

func (Context) Float64

func (c Context) Float64(key string, f float64) Context

Float64 adds the field key with f as a float64 to the logger context.

func (Context) Floats32

func (c Context) Floats32(key string, f []float32) Context

Floats32 adds the field key with f as a []float32 to the logger context.

func (Context) Floats64

func (c Context) Floats64(key string, f []float64) Context

Floats64 adds the field key with f as a []float64 to the logger context.

func (Context) IPAddr

func (c Context) IPAddr(key string, ip net.IP) Context

IPAddr adds IPv4 or IPv6 Address to the context

func (Context) IPPrefix

func (c Context) IPPrefix(key string, pfx net.IPNet) Context

IPPrefix adds IPv4 or IPv6 Prefix (address and mask) to the context

func (Context) Info

func (c Context) Info(args ...interface{})

func (Context) Infof

func (c Context) Infof(format string, args ...interface{})

func (Context) Int

func (c Context) Int(key string, i int) Context

Int adds the field key with i as a int to the logger context.

func (Context) Int16

func (c Context) Int16(key string, i int16) Context

Int16 adds the field key with i as a int16 to the logger context.

func (Context) Int32

func (c Context) Int32(key string, i int32) Context

Int32 adds the field key with i as a int32 to the logger context.

func (Context) Int64

func (c Context) Int64(key string, i int64) Context

Int64 adds the field key with i as a int64 to the logger context.

func (Context) Int8

func (c Context) Int8(key string, i int8) Context

Int8 adds the field key with i as a int8 to the logger context.

func (Context) Interface

func (c Context) Interface(key string, i interface{}) Context

Interface adds the field key with obj marshaled using reflection.

func (Context) Ints

func (c Context) Ints(key string, i []int) Context

Ints adds the field key with i as a []int to the logger context.

func (Context) Ints16

func (c Context) Ints16(key string, i []int16) Context

Ints16 adds the field key with i as a []int16 to the logger context.

func (Context) Ints32

func (c Context) Ints32(key string, i []int32) Context

Ints32 adds the field key with i as a []int32 to the logger context.

func (Context) Ints64

func (c Context) Ints64(key string, i []int64) Context

Ints64 adds the field key with i as a []int64 to the logger context.

func (Context) Ints8

func (c Context) Ints8(key string, i []int8) Context

Ints8 adds the field key with i as a []int8 to the logger context.

func (Context) Logger

func (c Context) Logger() NgrZeroLogger

Logger returns the logger with the context previously set.

func (Context) MACAddr

func (c Context) MACAddr(key string, ha net.HardwareAddr) Context

MACAddr adds MAC address to the context

func (Context) Panic

func (c Context) Panic(args ...interface{})

func (Context) Panicf

func (c Context) Panicf(format string, args ...interface{})

func (Context) Str

func (c Context) Str(key, val string) Context

Str adds the field key with val as a string to the logger context.

func (Context) Stringer

func (c Context) Stringer(key string, val fmt.Stringer) Context

Stringer adds the field key with val.String() (or null if val is nil) to the logger context.

func (Context) Strs

func (c Context) Strs(key string, vals []string) Context

Strs adds the field key with val as a string to the logger context.

func (Context) Time

func (c Context) Time(key string, t time.Time) Context

Time adds the field key with t formatted as string using zerolog.TimeFieldFormat.

func (Context) Times

func (c Context) Times(key string, t []time.Time) Context

Times adds the field key with t formatted as string using zerolog.TimeFieldFormat.

func (Context) Trace

func (c Context) Trace(args ...interface{})

func (Context) Tracef

func (c Context) Tracef(format string, args ...interface{})

func (Context) Type

func (c Context) Type(key string, val interface{}) Context

Type adds the field key with val's type using reflection.

func (Context) Uint

func (c Context) Uint(key string, i uint) Context

Uint adds the field key with i as a uint to the logger context.

func (Context) Uint16

func (c Context) Uint16(key string, i uint16) Context

Uint16 adds the field key with i as a uint16 to the logger context.

func (Context) Uint32

func (c Context) Uint32(key string, i uint32) Context

Uint32 adds the field key with i as a uint32 to the logger context.

func (Context) Uint64

func (c Context) Uint64(key string, i uint64) Context

Uint64 adds the field key with i as a uint64 to the logger context.

func (Context) Uint8

func (c Context) Uint8(key string, i uint8) Context

Uint8 adds the field key with i as a uint8 to the logger context.

func (Context) Uints

func (c Context) Uints(key string, i []uint) Context

Uints adds the field key with i as a []uint to the logger context.

func (Context) Uints16

func (c Context) Uints16(key string, i []uint16) Context

Uints16 adds the field key with i as a []uint16 to the logger context.

func (Context) Uints32

func (c Context) Uints32(key string, i []uint32) Context

Uints32 adds the field key with i as a []uint32 to the logger context.

func (Context) Uints64

func (c Context) Uints64(key string, i []uint64) Context

Uints64 adds the field key with i as a []uint64 to the logger context.

func (Context) Uints8

func (c Context) Uints8(key string, i []uint8) Context

Uints8 adds the field key with i as a []uint8 to the logger context.

func (Context) Warn

func (c Context) Warn(args ...interface{})

func (Context) Warnf

func (c Context) Warnf(format string, args ...interface{})

func (Context) Warning

func (c Context) Warning(args ...interface{})

func (Context) Warningf

func (c Context) Warningf(format string, args ...interface{})

type NgrZeroLogger

type NgrZeroLogger struct {
	Product   string
	Component string
	Version   string
	Hostname  string
	Address   string

	ShowProduct   atomic.Bool
	ShowComponent atomic.Bool
	ShowVersion   atomic.Bool
	ShowHostname  atomic.Bool
	ShowAddress   atomic.Bool
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(product, component, version, hostname, address string) NgrZeroLogger

func (*NgrZeroLogger) AddOutput

func (l *NgrZeroLogger) AddOutput(key string, w io.Writer)

func (NgrZeroLogger) Debug

func (l NgrZeroLogger) Debug(args ...interface{})

func (NgrZeroLogger) Debugf

func (l NgrZeroLogger) Debugf(format string, args ...interface{})

func (NgrZeroLogger) Error

func (l NgrZeroLogger) Error(args ...interface{})

func (NgrZeroLogger) Errorf

func (l NgrZeroLogger) Errorf(format string, args ...interface{})

func (NgrZeroLogger) Fatal

func (l NgrZeroLogger) Fatal(args ...interface{})

func (NgrZeroLogger) Fatalf

func (l NgrZeroLogger) Fatalf(format string, args ...interface{})

func (NgrZeroLogger) Info

func (l NgrZeroLogger) Info(args ...interface{})

func (NgrZeroLogger) Infof

func (l NgrZeroLogger) Infof(format string, args ...interface{})

func (*NgrZeroLogger) Level

func (l *NgrZeroLogger) Level(lvl zerolog.Level) NgrZeroLogger

Level creates a child logger with the minimum accepted level set to level.

func (NgrZeroLogger) Panic

func (l NgrZeroLogger) Panic(args ...interface{})

func (NgrZeroLogger) Panicf

func (l NgrZeroLogger) Panicf(format string, args ...interface{})

func (NgrZeroLogger) Print added in v2.0.1

func (l NgrZeroLogger) Print(args ...interface{})

Print sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Print.

func (NgrZeroLogger) Printf added in v2.0.1

func (l NgrZeroLogger) Printf(format string, args ...interface{})

Printf sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Printf.

func (NgrZeroLogger) Println added in v2.0.1

func (l NgrZeroLogger) Println(args ...interface{})

Println sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Println.

func (*NgrZeroLogger) RemoveOutput

func (l *NgrZeroLogger) RemoveOutput(key string)

RemoveOutput removes output by key

func (*NgrZeroLogger) SetOutput

func (l *NgrZeroLogger) SetOutput(w io.Writer)

func (NgrZeroLogger) Trace

func (l NgrZeroLogger) Trace(args ...interface{})

func (NgrZeroLogger) Tracef

func (l NgrZeroLogger) Tracef(format string, args ...interface{})

func (NgrZeroLogger) Warn

func (l NgrZeroLogger) Warn(args ...interface{})

func (NgrZeroLogger) Warnf

func (l NgrZeroLogger) Warnf(format string, args ...interface{})

func (NgrZeroLogger) Warning

func (l NgrZeroLogger) Warning(args ...interface{})

func (NgrZeroLogger) Warningf

func (l NgrZeroLogger) Warningf(format string, args ...interface{})

func (*NgrZeroLogger) With

func (l *NgrZeroLogger) With() Context

func (NgrZeroLogger) Write added in v2.0.1

func (l NgrZeroLogger) Write(p []byte) (n int, err error)

Write implements the io.Writer interface. This is useful to set as a writer for the standard library log.

Jump to

Keyboard shortcuts

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