Categorygithub.com/StephanHCB/go-autumn-logging
modulepackage
0.4.0
Repository: https://github.com/stephanhcb/go-autumn-logging.git
Documentation: pkg.go.dev

# README

go-autumn-logging

Pluggable logging support for 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 global singletons that are 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:

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")
}

# Packages

No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SetupNoLoggerForTesting is a setup function to use in tests that injects a do-nothing logger.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

CtxHasLogger lets you set up a function that checks whether a context contains a logger.
DefaultRequestIdValue lets you override the default value for the request id.
LogEventCallback lets you set up a callback that is called for every log event about to be written noinspection GoUnusedGlobalVariable.
Logger is the singleton instance of ContextAwareLoggingImplementation for use by any library and application to access the logger.
RequestIdRetriever is a singleton instance for use by implementations to obtain a tracing request id from a context.