auzerolog

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 7 Imported by: 7

README

go-autumn-logging-zerolog

Zerolog golang logging plugin for go-autumn-logging.

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, see go-autumn-logging.

About go-autumn-logging-zerolog

Implementation that pulls in logging using zerolog.

Features
  • context aware
  • provides context injection middleware for standard golang http server
  • fairly good performance
  • support for JSON and plaintext logging

Usage

Library Authors

Do NOT import this. You are doing it WRONG. You'll take away the application author's choice of logging libraries, which is the whole point of using go-autumn-logging in the first place.

Use go-autumn-logging (the api module) only!

Application Authors

You're all set with this dependency, just make sure you call one of the provided Setup functions to set up either JSON or plaintext logging. The simplest example for JSON logging

auzerolog.SetupJsonLogging("application-name")

and for plaintext logging:

auzerolog.SetupPlaintextLogging()

If you don't like our choice of fields or styling, you can easily customize everything by providing your own Setup-style function to call instead.

How To Use

Use call chaining style:

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

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

or if you prefer:

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 IsJson = false
View Source
var RecordedLogForTesting = new(bytes.Buffer)
View Source
var RequestIdFieldName = "request-id"

Functions

func AddLoggerToCtx added in v0.1.2

func AddLoggerToCtx(ctx context.Context) context.Context

func SetLogLevel added in v0.1.2

func SetLogLevel(level zerolog.Level)

func SetupForTesting

func SetupForTesting()

Setup function for testing that records log entries instead of writing them to console

func SetupJsonLogging

func SetupJsonLogging(serviceId string)

SetupJsonLogging configures go-autumn-logging to log via rs/zerolog using a subset of ECS see https://www.elastic.co/guide/en/ecs/1.4

func SetupPlaintextLogging

func SetupPlaintextLogging()

SetupPlaintextLogging configures go-autumn-logging to log via rs/zerolog using a simple plaintext logger

Types

This section is empty.

Directories

Path Synopsis
implementation

Jump to

Keyboard shortcuts

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