log

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 19 Imported by: 65

Documentation

Overview

Copyright (c) Microsoft Corporation. Licensed under the MIT license.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncoderConfig

func EncoderConfig() zapcore.EncoderConfig

func LogrLogger added in v1.2.1

func LogrLogger() logr.Logger

LogrLogger returns a logr.Logger backed by the global zap logger. This is useful for integrating with controller-runtime and other libraries that use logr.Logger, ensuring consistent log format across the application.

The returned logr.Logger is backed by a logr.LogSink that resolves the zap core on every call, so controller-runtime loggers set up before SetupZapLogger runs automatically start flowing to Application Insights once the zap global is initialized.

func SetDefaultSlog added in v1.2.1

func SetDefaultSlog()

SetDefaultSlog sets Go's global slog default to use the zap-backed handler. After calling this, slog.Default() returns a logger that routes through zap.

func SlogHandler added in v1.2.1

func SlogHandler() slog.Handler

SlogHandler returns an slog.Handler backed by the global zap core. All slog messages will flow through zap's pipeline (stdout + Application Insights). The returned handler resolves the global zap core on every call, so it keeps working even if registered (e.g. via logging.AddHandlers) before SetupZapLogger runs — once the global is initialized, records start flowing to AI.

func SlogLogger added in v1.2.1

func SlogLogger() *slog.Logger

SlogLogger returns a new *slog.Logger backed by the global zap core.

Types

type LogOpts

type LogOpts struct {
	Level                 string
	File                  bool
	FileName              string
	MaxFileSizeMB         int
	MaxBackups            int
	MaxAgeDays            int
	ApplicationInsightsID string
	EnableTelemetry       bool
}

func GetDefaultLogOpts

func GetDefaultLogOpts() *LogOpts

type ZapLogger

type ZapLogger struct {
	*zap.Logger
	// contains filtered or unexported fields
}

func Logger

func Logger() *ZapLogger

func SetupZapLogger

func SetupZapLogger(lOpts *LogOpts, persistentFields ...zap.Field) (*ZapLogger, error)

func (*ZapLogger) Close

func (l *ZapLogger) Close()

func (*ZapLogger) GetZappedMiddleware

func (l *ZapLogger) GetZappedMiddleware() func(next http.Handler) http.Handler

func (*ZapLogger) Named

func (l *ZapLogger) Named(name string) *ZapLogger

Jump to

Keyboard shortcuts

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