ulog

package module
v3.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2025 License: MIT Imports: 15 Imported by: 0

README

Build Status GoDoc codecov

ulog

A simple logging library which comes with an extension to log to influxDB (https://github.com/dunv/ulog2influx)

It comes with a default template which prints log-lines for example like this

2019-12-30 20:42:20.372 | ERROR | github.com/dunv/uauth/handlers.glob. CheckLoginHandler.go:59 (func1) | renderError [path: /api/checkLogin] token is expired by 141h11m24s
2019-12-30 20:42:20.372 | INFO  | uhttp.Handle | Registered http GET /api/monthReport
2019-12-30 20:42:20.372 | INFO  | main main.go:105 (main) | Serving at 0.0.0.0:8080
Setup
ulog.SetLogLevelFromString(cfg.LogLevel)
  • Additionally one can set up functions to skip (see doc)
  • Additionally one can set up functions to replace (see doc)
Usage examples
ulog.Trace("helloWorld")
ulog.Tracef("helloWorld %s", "today")
ulog.Debug("helloWorld")
ulog.Infof("helloWorld %s", "today")
ulog.Errorf("helloWorld %s", "today")
ulog.Fatalf("helloWorld %s", "today")
ulog.Panicf("helloWorld %s", "today")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(o ...Option)

func DPanic

func DPanic(v ...any)

func DPanicf

func DPanicf(template string, v ...any)

func Debug

func Debug(v ...any)

func DebugIfError

func DebugIfError(err error)

Logs the error to DEBUG-level if is not nil

func DebugStruct

func DebugStruct(taggedStruct any, prefix string)

Log out a struct line by line to Debug

func Debugf

func Debugf(template string, v ...any)

func Debugw added in v3.0.2

func Debugw(msg string, keysAndValues ...any)

func Dpanicw added in v3.0.2

func Dpanicw(msg string, keysAndValues ...any)

func Error

func Error(v ...any)

func ErrorStruct

func ErrorStruct(taggedStruct any, prefix string)

Log out a struct line by line to Error

func Errorf

func Errorf(template string, v ...any)

func Errorw added in v3.0.2

func Errorw(msg string, keysAndValues ...any)

func Fatal

func Fatal(v ...any)

func FatalIfError

func FatalIfError(err error)

Logs the error to FATAL-level if is not nil

func FatalIfErrorSecondArg

func FatalIfErrorSecondArg(input any, err error) any

Logs if error received as second argument to FATAL-level (and panicking after) is not nil (first argument is discarded)

func Fatalf

func Fatalf(template string, v ...any)

func Fatalw added in v3.0.2

func Fatalw(msg string, keysAndValues ...any)

func Info

func Info(v ...any)

func InfoIfError

func InfoIfError(err error)

Logs the error to INFO-level if is not nil

func InfoStruct

func InfoStruct(taggedStruct any, prefix string)

Log out a struct line by line to Info

func Infof

func Infof(template string, v ...any)

func Infofw added in v3.0.2

func Infofw(msg string, keysAndValues ...any)

func L

func L() *zap.Logger

func Log

func Log(lvl zapcore.Level, args ...any)

func LogByteArrayLineByLine

func LogByteArrayLineByLine(in []byte, f func(string, ...any), prefix ...string)

Logs a byteArray line by line

func LogByteArrayLineByLineToDebug

func LogByteArrayLineByLineToDebug(in []byte, prefix ...string)

Logs a byteArray line by line to Debug

func LogByteArrayLineByLineToError

func LogByteArrayLineByLineToError(in []byte, prefix ...string)

Logs a byteArray line by line to Error

func LogByteArrayLineByLineToInfo

func LogByteArrayLineByLineToInfo(in []byte, prefix ...string)

Logs a byteArray line by line to Info

func LogByteArrayLineByLineToWarn

func LogByteArrayLineByLineToWarn(in []byte, prefix ...string)

Logs a byteArray line by line to Warn

func LogEnvStruct

func LogEnvStruct(envStruct any, prefix string)

Helper function to log out a struct annotated with "env", "mask" and "warnIf" annotations Good to use with the "github.com/codingconcepts/env" package

func LogIfError

func LogIfError(err error)

Logs the error to ERROR-level if it is not nil

func LogIfErrorSecondArg

func LogIfErrorSecondArg(input any, err error) any

Logs if error received as second argument to ERROR-level is not nil (first argument is discarded)

func LogIfErrorToInfo

func LogIfErrorToInfo(err error)

Logs the error to INFO-level if it is not nil

func LogIfErrorToInfoSecondArg

func LogIfErrorToInfoSecondArg(_ any, err error)

Logs if error received as second argument to INFO-level is not nil (first argument is discarded)

func LogJSONStruct

func LogJSONStruct(envStruct any, prefix string)

Helper function to log out a struct annotated with "json", "mask" and "warnIf" annotations Good to use with the "encoding/json" package

func LogTaggedStructWithMaskingAndWarning

func LogTaggedStructWithMaskingAndWarning(
	taggedStruct any, tag string, maskTag string, warnTag string, prefix string, printHeaders bool,
	logger *zap.SugaredLogger,
)

Helper function to log out a struct should only be used if LogEnvStruct() or LogJSONStruct() do not meet your requirements

func Logf added in v3.0.4

func Logf(lvl zapcore.Level, template string, args ...any)

func Logw added in v3.0.4

func Logw(lvl zapcore.Level, msg string, keysAndValues ...any)

func Panic

func Panic(v ...any)

func PanicIfError

func PanicIfError(err error)

Logs the error to PANIC-level (and panicking after) if is not nil

func PanicIfErrorSecondArg

func PanicIfErrorSecondArg(input any, err error) any

Logs if error received as second argument to PANIC-level (and panicking after) is not nil (first argument is discarded)

func Panicf

func Panicf(template string, v ...any)

func Panicw added in v3.0.2

func Panicw(msg string, keysAndValues ...any)

func S

func S() *zap.SugaredLogger

func SkipOneL

func SkipOneL() *zap.Logger

func SkipOneS

func SkipOneS() *zap.SugaredLogger

func Warn

func Warn(v ...any)

func WarnIfError

func WarnIfError(err error)

Logs the error to WARN-level if is not nil

func WarnStruct

func WarnStruct(taggedStruct any, prefix string)

Log out a struct line by line to Warn

func Warnf

func Warnf(template string, v ...any)

func Warnw added in v3.0.2

func Warnw(msg string, keysAndValues ...any)

func With

func With(args ...any) *zap.SugaredLogger

Types

type DebugWriter

type DebugWriter struct{}

func (DebugWriter) Write

func (DebugWriter) Write(p []byte) (int, error)

type ErrorWriter

type ErrorWriter struct{}

func (ErrorWriter) Write

func (ErrorWriter) Write(p []byte) (int, error)

type FatalWriter

type FatalWriter struct{}

func (FatalWriter) Write

func (FatalWriter) Write(p []byte) (int, error)

type InfoWriter

type InfoWriter struct{}

func (InfoWriter) Write

func (InfoWriter) Write(p []byte) (int, error)

type Logger

type Logger interface {
	Fatalln(v ...any)
	Panicln(v ...any)
	Print(v ...any)
	Printf(format string, v ...any)
	Println(v ...any)
	Debug(v ...any)
	Debugf(template string, v ...any)
	Debugw(msg string, keysAndValues ...any)
	Info(v ...any)
	Infof(template string, v ...any)
	Infow(msg string, keysAndValues ...any)
	Warn(v ...any)
	Warnf(template string, v ...any)
	Warnw(msg string, keysAndValues ...any)
	Error(v ...any)
	Errorf(template string, v ...any)
	Errorw(msg string, keysAndValues ...any)
	Fatal(v ...any)
	Fatalf(template string, v ...any)
	Fatalw(msg string, keysAndValues ...any)
	DPanic(v ...any)
	DPanicf(template string, v ...any)
	DPanicw(msg string, keysAndValues ...any)
	Panic(v ...any)
	Panicf(template string, v ...any)
	Panicw(msg string, keysAndValues ...any)
	Log(lvl zapcore.Level, args ...any)
	Logf(lvl zapcore.Level, template string, args ...any)
	Logw(lvl zapcore.Level, msg string, keysAndValues ...any)
}

convenience for passing the logger to third-party libs

func NewDefaultLogger

func NewDefaultLogger() Logger

func NewDiscardLogger added in v3.0.5

func NewDiscardLogger() Logger

func NewLogger

func NewLogger(log *zap.SugaredLogger) Logger

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithAdditionalCores

func WithAdditionalCores(cores ...zapcore.Core) Option

Default: nil

func WithCallerFieldWidth

func WithCallerFieldWidth(fieldWidth int) Option

Default: -1 (no width)

func WithLogLevel

func WithLogLevel(lvl string) Option

Default: info

func WithNewlineReplacement

func WithNewlineReplacement(newlineReplacement string) Option

Default: ""

func WithRedirectOutput

func WithRedirectOutput(w io.Writer) Option

Default: os.Stdout

func WithStripAdditionalFields

func WithStripAdditionalFields(stripAdditionalFields bool) Option

Default: true

type PanicWriter

type PanicWriter struct{}

func (PanicWriter) Write

func (PanicWriter) Write(p []byte) (int, error)

type WarnWriter

type WarnWriter struct{}

func (WarnWriter) Write

func (WarnWriter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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