logging

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

README

Logging Package

This package implements a common logging package for Infrastructure as a Service applications, based on zerolog.

Controlling the Log Level

This logging package defines a CLI flag named -globalLogLevel. As the name suggests, it sets the global log level exposed by zerolog. Apps that want to expose this flag, must call flag.Parse() in their main function. This is the preferred approach to ensure a consistent UX. Should an app need to deviate, it can call zerolog.SetGlobalLevel(...) as required.

Output Formatting

By default, logging output is in machine-readable JSON format. For use cases where a more human-readable format is desired, the HUMAN environment variable should be set.

Security Logging

Logging package exposes a tag called McSec which can be used to identify security events happening across MC components

// zlog is MCLogger, printing a security event
zlog.McSec().Info().Msgf("Client %s authorized", client.UUID)

// zlog is MCCtxLogger, printing a security event
zlog := zlog.TraceCtx(ctx)
zlog.McSec().Info().Msgf("Client %s authorized", client.UUID)

Error Logging

Logging package exposes utilities to append error into the logs which can be easily scraped by external tools

// zlog is MCLogger, printing a security event and error
err := errors.Errorfc(codes.PermissionDenied, "Permission denied for client: %s", "1")
zlog.McSec().McErr(err).Msg("")

// zlog is MCCtxLogger, printing a security event and error
zlog := zlog.TraceCtx(ctx)
zlog.McSec().McErr(err).Msg("")

// zlog is MCLogger, printing a security event and error string
zlog.McSec().McError("Permission denied for client: %s", "1").Msg("CreateResource")

// zlog is MCCtxLogger, printing a security event and error string
zlog := zlog.TraceCtx(ctx)
zlog.McSec().McError("Permission denied for client: %s", "1").Msg("CreateResource")

Documentation

Index

Constants

View Source
const RFC3339Micro = "2006-01-02T15:04:05.000000Z07:00"

RFC3339Micro represents a time format similar to time.RFC3339Nano but only accurate to microseconds and keeping trailing zeros

Variables

This section is empty.

Functions

This section is empty.

Types

type MCCtxLogger

type MCCtxLogger struct {
	zerolog.Logger
}

func (*MCCtxLogger) McErr

func (l *MCCtxLogger) McErr(err error) *zerolog.Event

McErr is an extension for MCCtxLogger intended to be used for error logging.

func (*MCCtxLogger) McError

func (l *MCCtxLogger) McError(format string, args ...interface{}) *zerolog.Event

McError is an extension for MCCtxLogger intended to be used for logging of inline errors.

func (*MCCtxLogger) McSec

func (l *MCCtxLogger) McSec() *MCCtxLogger

McSec is a logging decorator MCCtxLogger intended to be used for security related events.

type MCLogger

type MCLogger struct {
	zerolog.Logger
}

func GetLogger

func GetLogger(component string) MCLogger

func (*MCLogger) McErr

func (l *MCLogger) McErr(err error) *zerolog.Event

McErr is an extension for MCLogger intended to be used for error logging.

func (*MCLogger) McError

func (l *MCLogger) McError(format string, args ...interface{}) *zerolog.Event

McError is an extension for MCLogger intended to be used for logging of inline errors.

func (*MCLogger) McSec

func (l *MCLogger) McSec() *MCLogger

McSec is a logging decorator for MCLogger intended to be used for security related events.

func (MCLogger) TraceCtx

func (l MCLogger) TraceCtx(ctx context.Context) MCCtxLogger

Jump to

Keyboard shortcuts

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