ulog

package module
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2019 License: MIT Imports: 13 Imported by: 3

README

Build Status

ulog

Documentation and (hopefully soon examples) can be found here: https://godoc.org/github.com/dunv/ulog

A simple logging library which supports predefined fields

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddReplaceFunction

func AddReplaceFunction(fnToBeReplaced string, replaceWithFn string)

Add a single replace function. This is used to make log-output origin easier to identify. Instead of getting a filename, package and function, a desired identifier can be chosen. for example

ulog.AddReplaceFunction("github.com/dunv/uhttp/middlewares.AddLogging.func1", "uhttp.Logging")
ulog.AddReplaceFunction("github.com/dunv/uhttp.Handle", "uhttp.Handle")

func AddReplaceFunctions

func AddReplaceFunctions(m map[string]string)

Add a multiple replace functions. See AddReplaceFunction for more detail

func AddSkipFunctions

func AddSkipFunctions(_skipFunctions ...string)

// Make expected output (which is only for info, not for debugging) more readable Add skipFunctions. These functions will be skipped, when trying to determine the origin of a log-line. This way helper functions which are in use for multiple different origins can be omitted. For example

ulog.AddSkipFunctions(
	"github.com/dunv/uhttp.RenderError",
	"github.com/dunv/uhttp/helpers.RenderError",
	"github.com/dunv/uhttp.RenderErrorWithStatusCode",
	"github.com/dunv/uhttp/helpers.RenderErrorWithStatusCode",
	"github.com/dunv/uhttp.RenderMessage",
	"github.com/dunv/uhttp/helpers.RenderMessage",
	"github.com/dunv/uhttp.RenderMessageWithStatusCode",
	"github.com/dunv/uhttp/helpers.RenderMessageWithStatusCode",
	"github.com/dunv/uhttp.renderMessageWithStatusCode",
	"github.com/dunv/uhttp/helpers.renderMessageWithStatusCode",
	"github.com/dunv/uhttp/helpers.renderErrorWithStatusCode",
	"github.com/dunv/uhttp.renderErrorWithStatusCode",
)

func Debug

func Debug(v ...interface{})

func Debugf

func Debugf(fmtString string, v ...interface{})

func Error

func Error(v ...interface{})

func Errorf

func Errorf(fmtString string, v ...interface{})

func Fatal

func Fatal(v ...interface{})

func Fatalf

func Fatalf(fmtString string, v ...interface{})

func Info

func Info(v ...interface{})

func Infof

func Infof(fmtString string, v ...interface{})

func LogEnvStruct

func LogEnvStruct(envStruct interface{}, 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(_ interface{}, err error)

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(_ interface{}, err error)

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

func NewErrorLogger added in v1.0.5

func NewErrorLogger(ulogger *ULogger) *log.Logger

Helper for instantiating UErrorWriter

func NewInfoLogger added in v1.0.5

func NewInfoLogger(ulogger *ULogger) *log.Logger

Helper for instantiating UInfoWriter

func Panic

func Panic(v ...interface{})

func PanicIfError added in v1.0.3

func PanicIfError(err error)

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

func PanicIfErrorSecondArg added in v1.0.3

func PanicIfErrorSecondArg(_ interface{}, err error)

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

func Panicf

func Panicf(fmtString string, v ...interface{})

func RemoveWriter added in v1.0.6

func RemoveWriter(name string) error

Remove a writer

func ReplaceFunctions

func ReplaceFunctions() map[string]string

Get replace-functions

func ResetFormat added in v1.0.8

func ResetFormat()

Use original logging format

func SetDebug

func SetDebug()

Enable debugging skipFunctions and ReplaceFunctions

func SetFormatString

func SetFormatString(_fmtString string)

Use custom logging format (using text/template) The original is

"{{ .Time }} | {{ .Level }} | {{ .Package }}{{ if .File }} {{ .File }}{{ end }}{{ if .Line }}:{{ .Line }}{{ end }}{{ if .Function }} ({{ .Function }}){{ end }} | {{ .Message }}\n"

Available vars are

  • Time
  • Level
  • Package
  • File (not always available)
  • Line (not always available)
  • Function (not always available)
  • Message

func SetLogLevel

func SetLogLevel(_level LogLevel)

Set logLevel

func SetLogLevelFromString

func SetLogLevelFromString(levelRaw string)

Set logLevel from string takes "trace", "debug", "info", "information", "warn", "warning", "error" and "fatal" as arguments. Case does not matter

func SetTimestampFormat

func SetTimestampFormat(_tsFormat string)

Set a different format for the timestamp the original is "2006-01-02 15:04:05.000"

func SetWriter

func SetWriter(_writer io.Writer, name *string)

Add or replace a writer if name is nil the default writer will be replaced

func SkipFunctions

func SkipFunctions() []string

Get currently configured skipFunctions

func Trace

func Trace(v ...interface{})

func Tracef

func Tracef(fmtString string, v ...interface{})

func UnsetDebug

func UnsetDebug()

Disable debugging skipFunctions and ReplaceFunctions

func Warn

func Warn(v ...interface{})

func Warnf

func Warnf(fmtString string, v ...interface{})

Types

type LogEntry

type LogEntry struct {
	Time     string
	Level    logLevelString
	Package  string
	File     string
	Line     int
	Function string
	Message  string
}

type LogLevel

type LogLevel int

LogLevel for the application

const (
	LEVEL_TRACE LogLevel = iota
	LEVEL_DEBUG
	LEVEL_INFO
	LEVEL_WARNING
	LEVEL_ERROR
	LEVEL_FATAL
)

func GetLogLevel

func GetLogLevel() LogLevel

Get currently set logLevel

type UErrorWriter added in v1.0.5

type UErrorWriter struct {
	Logger *ULogger
}

A writer (implementing the io.Writer interface) which logs everything to its configured logger and to ERROR-level If not logger is configured, the default logger will be used

func (UErrorWriter) Write added in v1.0.5

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

type UInfoWriter added in v1.0.5

type UInfoWriter struct {
	Logger *ULogger
}

A writer (implementing the io.Writer interface) which logs everything to its configured logger and to INFO-level If not logger is configured, the default logger will be used

func (UInfoWriter) Write added in v1.0.5

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

type ULog

type ULog struct{}

func NewUlog

func NewUlog() *ULog

func (ULog) Debug

func (l ULog) Debug(v ...interface{})

func (ULog) Debugf

func (l ULog) Debugf(fmtString string, v ...interface{})

func (ULog) Error

func (l ULog) Error(v ...interface{})

func (ULog) Errorf

func (l ULog) Errorf(fmtString string, v ...interface{})

func (ULog) Fatal

func (l ULog) Fatal(v ...interface{})

func (ULog) Fatalf

func (l ULog) Fatalf(fmtString string, v ...interface{})

func (ULog) Info

func (l ULog) Info(v ...interface{})

func (ULog) Infof

func (l ULog) Infof(fmtString string, v ...interface{})

func (ULog) LogIfError

func (l ULog) LogIfError(err error)

func (ULog) LogIfErrorSecondArg

func (l ULog) LogIfErrorSecondArg(tmp interface{}, err error)

func (ULog) LogIfErrorToInfo

func (l ULog) LogIfErrorToInfo(err error)

func (ULog) LogIfErrorToInfoSecondArg

func (l ULog) LogIfErrorToInfoSecondArg(tmp interface{}, err error)

func (ULog) Panic

func (l ULog) Panic(v ...interface{})

func (ULog) PanicIfError added in v1.0.3

func (l ULog) PanicIfError(err error)

func (ULog) PanicIfErrorSecondArg added in v1.0.3

func (l ULog) PanicIfErrorSecondArg(tmp interface{}, err error)

func (ULog) Panicf

func (l ULog) Panicf(fmtString string, v ...interface{})

func (ULog) Trace

func (l ULog) Trace(v ...interface{})

func (ULog) Tracef

func (l ULog) Tracef(fmtString string, v ...interface{})

func (ULog) Warn

func (l ULog) Warn(v ...interface{})

func (ULog) Warnf

func (l ULog) Warnf(fmtString string, v ...interface{})

type ULogger

type ULogger interface {
	Trace(v ...interface{})
	Tracef(fmtString string, v ...interface{})
	Debug(v ...interface{})
	Debugf(fmtString string, v ...interface{})
	Info(v ...interface{})
	Infof(fmtString string, v ...interface{})
	Warn(v ...interface{})
	Warnf(fmtString string, v ...interface{})
	Error(v ...interface{})
	Errorf(fmtString string, v ...interface{})
	Panic(v ...interface{})
	Panicf(fmtString string, v ...interface{})
	Fatal(v ...interface{})
	Fatalf(fmtString string, v ...interface{})
	LogIfError(err error)
	LogIfErrorSecondArg(tmp interface{}, err error)
	PanicIfError(err error)
	PanicIfErrorSecondArg(tmp interface{}, err error)
	LogIfErrorToInfo(err error)
	LogIfErrorToInfoSecondArg(tmp interface{}, err error)
}

Jump to

Keyboard shortcuts

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