Version: v0.0.0-...-afa1830 Latest Latest

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

Go to latest
Published: Apr 13, 2021 License: AGPL-3.0 Imports: 6 Imported by: 0


Logger Package

Logger package should be used by all our services to share same log format or storage.

Sharing a log format allows us to collect process them easily in order to build metrics and other features around it.

Echo Logger Middlewares

We use two different loggers:

  • The default echo logger, instantiated by the NewLogger() middleware. It logs:
    • the requests (automatically)
  • A zerolog logger, instantiated by the NewZerologLogger() middleware. It logs:
    • the errors (automatically, when a merr is returned)
    • the logs specified in the service with logger.FromCtx(ctx) (logger being import "gitlab.misakey.dev/misakey/backend/api/src/sdk/logger")

Service Logger

When you are not in a request scope and have no access to derived context.Context, you can instantiate a zerolog logger with logger.ZerologLogger(). It will automatically add the service_name and service_version fields extracted from the running binary and VERSION environment variable.




This section is empty.


This section is empty.


func FromCtx

func FromCtx(ctx context.Context) *zerolog.Logger

FromCtx returns the context logger

func GetEchoFormat

func GetEchoFormat() string

GetEchoFormat returns echo format services should use.

func GetLogLevel

func GetLogLevel(level string) zerolog.Level

GetLogLevel returns the zerolog Level corresponding to the string level

func LogMemUsage

func LogMemUsage(ctx context.Context, desc string)

LogMemUsage whenever a debug is required somewhere NOTE: don't forget to call runtime.GC() to trigger the garbage collector between stats retrievals

func SetLogger

func SetLogger(ctx context.Context, logger *zerolog.Logger) context.Context

SetLogger returns ctx with Logger set inside it using ctxKey

func ZerologLogger

func ZerologLogger(level string) zerolog.Logger

ZerologLogger instantiates and returns a new configured logger


type CtxKey

type CtxKey struct{}

CtxKey ...

Source Files

Jump to

Keyboard shortcuts

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