Categorygithub.com/coopnorge/go-logger
modulepackage
0.11.3
Repository: https://github.com/coopnorge/go-logger.git
Documentation: pkg.go.dev

# README

go-logger

This Go package is used to offer a unified logging interface among projects.

Documentation

There usage documentation in docs. Development documentation is in this file.

Development workflow

Validate

docker compose run --rm golang-devtools validate

Other targets

docker compose run --rm golang-devtools help

Mocks

To generate or update mocks use gomockhandler. gomockhandler is provided by golang-devtools.

Check mocks

docker compose run --rm golang-devtools gomockhandler -config ./gomockhandler.json check

Generate / Update mocks

docker compose run --rm golang-devtools gomockhandler -config ./gomockhandler.json mockgen

User documentation

User documentation is build using TechDocs and published to Inventory.

To list the commands available for the TechDocs image:

docker compose run --rm help

For more information see the TechDocs Engineering Image.

Documentation validation

To Validate changed documentation:

docker compose run --rm techdocs validate

To validate all documentation:

docker compose run --rm techdocs validate MARKDOWN_FILES=docs/

Documentation preview

To preview the documentation:

docker compose up techdocs

# Packages

No description provided by the author

# Functions

ConfigureGlobalLogger applies supplied logger options to the global logger.
Debug uses global logger to log payload on "debug" level.
Debugf uses global logger to log payload on "debug" level.
Error uses global logger to log payload on "error" level.
Errorf uses global logger to log payload on "error" level.
Fatal uses global logger to log payload on "fatal" level.
Fatalf uses global logger to log payload on "fatal" level.
Global logger that can be accessed without prior instantiation.
Info uses global logger to log payload on "info" level.
Infof uses global logger to log payload on "info" level.
LevelNameToLevel converts a named log level to the Level type.
New creates and returns a new logger with supplied options.
SetLevel sets minimum log level for global logger.
SetNowFunc sets `now` func user by global logger.
SetOutput changes global logger's output.
SetReportCaller allows controlling if caller info should be attached to logs by global logger.
Warn uses global logger to log payload on "warn" level.
Warnf uses global logger to log payload on "warn" level.
WithContext creates log entry using global logger.
WithError is a convenience wrapper for WithField("err", err).
WithField creates log entry using global logger.
WithFields creates log entry using global logger.
WithHook allows for connecting a hook to the logger, which will be triggered on all log-entries.
WithHookFunc allows for connecting a hook to the logger, which will be triggered on all log-entries.
WithLevel sets minimum level for filtering logs.
WithLevelFromEnv allows to Configure Logger from Environment Variable.
WithLevelName sets minimum level for filtering logs by name.
WithNowFunc overrides default function used to determine current time.
WithOutput overrides default output the logs are written to.
WithReportCaller allows enabling/disabling including calling method in the log entry.

# Constants

LevelDebug should only be used in dev/test environments.
LevelError isto be used for recoverable errors that limit the service's functionality, eg timeouts.
LevelFatal is to be used to log predictable errors that make the service unusable, eg misconfiguration.
LevelInfo is to be used for monitoring successful interactions, eg run time or job result.
LevelWarn is to be used for non-critical errors that may require some attention.

# Structs

Entry
Entry represents a logging entry and all supported method we use.
HookEntry contains the fields provided for mutation in a hook.
Logger is our logger with the needed structured logger we use.

# Interfaces

Hook defines the interface a custom Hook needs to implement.
LoggerOption defines an applicator interface.

# Type aliases

Fields type, used to pass to `WithFields`.
HookFunc can be used to convert a simple function to implement the Hook interface.
Level is an integer representation of the logging level.
LoggerOptionFunc defines a function which modifies a logger.
NowFunc is a typedef for a function which returns the current time.