aulogging

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: MIT Imports: 3 Imported by: 33

README

go-autumn-logging

Pluggable logging support for go-autumn.

About go-autumn

A collection of libraries for enterprise microservices in golang that

  • is heavily inspired by Spring Boot / Spring Cloud
  • is very opinionated
  • names modules by what they do
  • unlike Spring Boot avoids certain types of auto-magical behaviour
  • is not a library monolith, that is every part only depends on the api parts of the other components at most, and the api parts do not add any dependencies.

Fall is my favourite season, so I'm calling it go-autumn.

About go-autumn-logging

An interface for pluggable logging support with context integration.

This module has zero dependencies, it just provides an interface and a global singleton that is externally supplied with an implementation of said interface.

Any library or go-autumn module that wants to use context-aware logging should depend on this module, thereby not pulling in any particular logging implementation.

The application can then pull in the relevant go-autumn-logging submodule, such as go-autumn-logging-zerolog.

Usage

Library Authors

If you are writing a library, import only this module in your dependencies, none of the other go-autumn-logging-* modules that actually bring in a logging library.

In your testing code, call aulogging.SetupNoLoggerForTesting() to avoid the nil pointer dereference.

Application Authors

If you are writing an application, import one of the modules that actually bring in a logging library, such as go-autumn-logging-zerolog. These modules will provide an implementation and place it in the Logger variable.

Of course, you can also provide your own implementation of the LoggingImplementation interface, just set the Logger global singleton to an instance of your implementation.

Then just use the Logger, both during application runtime and tests.

How To Use

Context aware logging is now as simple as:

import "github.com/StephanHCB/go-autumn-logging"

func someFunction(ctx context.Context) {
    aulogging.Logger.Ctx(ctx).Warn().Print("something bad has happened")
}

There are convenience functions for those who prefer the function call with arguments style. This does the same thing as above:

import "github.com/StephanHCB/go-autumn-logging"

func someFunction(ctx context.Context) {
    aulogging.Warn(ctx, "something bad has happened")
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRequestIdValue = ""

DefaultRequestIdValue lets you override the default value for the request id.

This is useful for console logging if you want your request ids to align.

noinspection GoUnusedGlobalVariable

View Source
var LogEventCallback auloggingapi.LogEventCallbackFunc

LogEventCallback lets you set up a callback that is called for every log event about to be written

noinspection GoUnusedGlobalVariable

View Source
var Logger auloggingapi.LoggingImplementation

Logger is the singleton instance of ContextAwareLoggingImplementation for use by any library and application to access the logger.

See convenience.go for some examples of how to emit log entries.

This global singleton is assigned outside this module. This is so the application author can choose which logging library to use.

Library authors: only depend on go-autumn-logging and do not touch this variable.

Application authors: depend on go-autumn-logging-zerolog (or some other variant) which will set this variable on startup, and then you'll be using zerolog.

View Source
var RequestIdRetriever auloggingapi.RequestIdRetrieverFunc

RequestIdRetriever is a singleton instance for use by implementations to obtain a tracing request id from a context.

This global singleton is assigned outside this module. Assigning it is optional. If an assignment is made, such as by some of the go-autumn tracing implementations, then request ids will show up in logs for loggers that support it.

Library authors: only depend on go-autumn-logging and do not touch this variable.

Application authors: either assign this yourself, or depend on one of the tracing modules.

noinspection GoUnusedGlobalVariable

Functions

func Debug

func Debug(ctx context.Context, v ...interface{})

func DebugErr

func DebugErr(ctx context.Context, err error, v ...interface{})

func DebugErrf

func DebugErrf(ctx context.Context, err error, format string, v ...interface{})

func Debugf

func Debugf(ctx context.Context, format string, v ...interface{})

func Error

func Error(ctx context.Context, v ...interface{})

func ErrorErr

func ErrorErr(ctx context.Context, err error, v ...interface{})

func ErrorErrf

func ErrorErrf(ctx context.Context, err error, format string, v ...interface{})

func Errorf

func Errorf(ctx context.Context, format string, v ...interface{})

func Fatal

func Fatal(ctx context.Context, v ...interface{})

func FatalErr

func FatalErr(ctx context.Context, err error, v ...interface{})

func FatalErrf

func FatalErrf(ctx context.Context, err error, format string, v ...interface{})

func Fatalf

func Fatalf(ctx context.Context, format string, v ...interface{})

func Info

func Info(ctx context.Context, v ...interface{})

func InfoErr

func InfoErr(ctx context.Context, err error, v ...interface{})

func InfoErrf

func InfoErrf(ctx context.Context, err error, format string, v ...interface{})

func Infof

func Infof(ctx context.Context, format string, v ...interface{})

func SetupNoLoggerForTesting

func SetupNoLoggerForTesting()

setup function to use in tests that injects a do-nothing logger. You will need this if you are writing a library.

see convenience_test.go for an example how to use this.

func Trace

func Trace(ctx context.Context, v ...interface{})

func TraceErr

func TraceErr(ctx context.Context, err error, v ...interface{})

func TraceErrf

func TraceErrf(ctx context.Context, err error, format string, v ...interface{})

func Tracef

func Tracef(ctx context.Context, format string, v ...interface{})

func Warn

func Warn(ctx context.Context, v ...interface{})

func WarnErr

func WarnErr(ctx context.Context, err error, v ...interface{})

func WarnErrf

func WarnErrf(ctx context.Context, err error, format string, v ...interface{})

func Warnf

func Warnf(ctx context.Context, format string, v ...interface{})

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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