Documentation
¶
Index ¶
- func AddReplaceFunction(fnToBeReplaced string, replaceWithFn string)
- func AddReplaceFunctions(m map[string]string)
- func AddSkipFunctions(_skipFunctions ...string)
- func Debug(v ...interface{})
- func DebugIfError(err error)
- func Debugf(fmtString string, v ...interface{})
- func DisableColors()
- func Error(v ...interface{})
- func Errorf(fmtString string, v ...interface{})
- func Fatal(v ...interface{})
- func FatalIfError(err error)
- func FatalIfErrorSecondArg(input interface{}, err error) interface{}
- func Fatalf(fmtString string, v ...interface{})
- func Info(v ...interface{})
- func InfoIfError(err error)
- func Infof(fmtString string, v ...interface{})
- func LogByteArrayLineByLine(in []byte, f func(string, ...interface{}), prefix ...string)
- func LogByteArrayLineByLineToDebug(in []byte, prefix ...string)
- func LogByteArrayLineByLineToError(in []byte, prefix ...string)
- func LogByteArrayLineByLineToInfo(in []byte, prefix ...string)
- func LogByteArrayLineByLineToTrace(in []byte, prefix ...string)
- func LogByteArrayLineByLineToWarn(in []byte, prefix ...string)
- func LogEnvStruct(envStruct interface{}, prefix string)
- func LogIfError(err error)
- func LogIfErrorSecondArg(input interface{}, err error) interface{}
- func LogIfErrorToInfo(err error)
- func LogIfErrorToInfoSecondArg(_ interface{}, err error)
- func LogJSONStruct(envStruct interface{}, prefix string)
- func LogWithLevel(level LogLevel, v ...interface{})
- func LogWithLevelf(level LogLevel, fmtString string, v ...interface{})
- func NewErrorLogger(ulogger *ULogger) *log.Logger
- func NewInfoLogger(ulogger *ULogger) *log.Logger
- func Panic(v interface{})
- func PanicIfError(err error)
- func PanicIfErrorSecondArg(input interface{}, err error) interface{}
- func Panicf(fmtString string, v ...interface{})
- func RemoveWriter(name string) error
- func ReplaceFunctions() map[string]string
- func ResetFormat()
- func ResetReplaceFunctions()
- func ResetSkipFunctions()
- func SetDebug()
- func SetFormatString(_fmtString string)
- func SetLogLevel(_level LogLevel)
- func SetLogLevelFromString(levelRaw string)
- func SetTimestampFormat(_tsFormat string)
- func SetWriter(_writer io.Writer, name *string)
- func SkipFunctions() []string
- func Trace(v ...interface{})
- func TraceIfError(err error)
- func Tracef(fmtString string, v ...interface{})
- func UnsetDebug()
- func Warn(v ...interface{})
- func WarnIfError(err error)
- func Warnf(fmtString string, v ...interface{})
- type LogEntry
- type LogLevel
- type UErrorWriter
- type UInfoWriter
- type ULog
- func (l ULog) Debug(v ...interface{})
- func (l ULog) Debugf(fmtString string, v ...interface{})
- func (l ULog) Error(v ...interface{})
- func (l ULog) Errorf(fmtString string, v ...interface{})
- func (l ULog) Fatal(v ...interface{})
- func (l ULog) Fatalf(fmtString string, v ...interface{})
- func (l ULog) Info(v ...interface{})
- func (l ULog) Infof(fmtString string, v ...interface{})
- func (l ULog) LogIfError(err error)
- func (l ULog) LogIfErrorSecondArg(tmp interface{}, err error)
- func (l ULog) LogIfErrorToInfo(err error)
- func (l ULog) LogIfErrorToInfoSecondArg(tmp interface{}, err error)
- func (l ULog) LogWithLevel(customLevel LogLevel, v ...interface{})
- func (l ULog) LogWithLevelf(customLevel LogLevel, customFmtString string, v ...interface{})
- func (l ULog) Panic(v interface{})
- func (l ULog) PanicIfError(err error)
- func (l ULog) PanicIfErrorSecondArg(tmp interface{}, err error)
- func (l ULog) Trace(v ...interface{})
- func (l ULog) Tracef(fmtString string, v ...interface{})
- func (l ULog) Warn(v ...interface{})
- func (l ULog) Warnf(fmtString string, v ...interface{})
- type ULogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddReplaceFunction ¶
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 ¶
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 DebugIfError ¶ added in v1.0.23
func DebugIfError(err error)
Logs the error to DEBUG-level if is not nil
func DisableColors ¶ added in v1.0.29
func DisableColors()
func FatalIfError ¶ added in v1.0.23
func FatalIfError(err error)
Logs the error to FATAL-level if is not nil
func FatalIfErrorSecondArg ¶ added in v1.0.23
func FatalIfErrorSecondArg(input interface{}, err error) interface{}
Logs if error received as second argument to FATAL-level (and panicking after) is not nil (first argument is discarded)
func InfoIfError ¶ added in v1.0.23
func InfoIfError(err error)
Logs the error to INFO-level if is not nil
func LogByteArrayLineByLine ¶ added in v1.0.22
Logs a byteArray line by line
func LogByteArrayLineByLineToDebug ¶ added in v1.0.22
Logs a byteArray line by line to Info
func LogByteArrayLineByLineToError ¶ added in v1.0.22
Logs a byteArray line by line to Error
func LogByteArrayLineByLineToInfo ¶ added in v1.0.22
Logs a byteArray line by line to Info
func LogByteArrayLineByLineToTrace ¶ added in v1.0.22
Logs a byteArray line by line to Trace
func LogByteArrayLineByLineToWarn ¶ added in v1.0.22
Logs a byteArray line by line to Warn
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 LogIfErrorSecondArg ¶
func LogIfErrorSecondArg(input interface{}, err error) interface{}
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 LogJSONStruct ¶ added in v1.0.24
func LogJSONStruct(envStruct interface{}, 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 LogWithLevel ¶ added in v1.0.14
func LogWithLevel(level LogLevel, v ...interface{})
func LogWithLevelf ¶ added in v1.0.14
func NewErrorLogger ¶ added in v1.0.5
Helper for instantiating UErrorWriter
func NewInfoLogger ¶ added in v1.0.5
Helper for instantiating UInfoWriter
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(input interface{}, err error) interface{}
Logs if error received as second argument to PANIC-level (and panicking after) is not nil (first argument is discarded)
func ResetSkipFunctions ¶ added in v1.0.26
func ResetSkipFunctions()
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 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 TraceIfError ¶ added in v1.0.23
func TraceIfError(err error)
Logs the error to TRACE-level if is not nil
func WarnIfError ¶ added in v1.0.23
func WarnIfError(err error)
Logs the error to WARN-level if is not nil
Types ¶
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
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
type ULog ¶
type ULog struct{}
A struct satisfying the ULogger interface. Currently only one global config for ulog is supported. This ULog cannot have a different configuration yet
func (ULog) LogIfError ¶
func (ULog) LogIfErrorSecondArg ¶
func (ULog) LogIfErrorToInfo ¶
func (ULog) LogIfErrorToInfoSecondArg ¶
func (ULog) LogWithLevel ¶ added in v1.0.14
func (ULog) LogWithLevelf ¶ added in v1.0.14
func (ULog) PanicIfError ¶ added in v1.0.3
func (ULog) PanicIfErrorSecondArg ¶ added in v1.0.3
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{}) Fatal(v ...interface{}) Fatalf(fmtString string, v ...interface{}) LogWithLevel(level LogLevel, v ...interface{}) LogWithLevelf(level LogLevel, 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) }
Interface containing all log-helper methods