ctxz

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 6 Imported by: 3

Documentation

Overview

Package ctxz implements wrapper to report aggregated messages for github.com/bool64/ctxd.Logger.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Observer

type Observer struct {
	// contains filtered or unexported fields
}

Observer keeps track of logged messages.

func NewObserver

func NewObserver(logger ctxd.Logger, conf ...logz.Config) Observer

NewObserver initializes Observer instance.

Example
package main

import (
	"context"
	"net/http"
	"os"
	"time"

	"github.com/bool64/ctxd"
	"github.com/bool64/logz"
	"github.com/bool64/logz/ctxz"
	"github.com/bool64/logz/logzpage"
)

func main() {
	var logger ctxd.Logger

	lz := ctxz.NewObserver(logger, logz.Config{
		MaxCardinality:      100,
		MaxSamples:          50,
		DistRetentionPeriod: 72 * time.Hour,
	})
	logger = lz

	ctx := context.TODO()

	logger.Debug(ctx, "starting example")
	logger.Info(ctx, "sample info", "one", 1, "two", 2)
	logger.Error(ctx, "unexpected end of the world")

	logger.Important(ctx, "starting server at http://localhost:6060/")

	err := http.ListenAndServe("0.0.0.0:6060", logzpage.Handler(lz.LevelObservers()...))
	if err != nil {
		logger.Error(ctx, err.Error())
		os.Exit(1)
	}
}
Output:

func (Observer) CtxdLogger

func (o Observer) CtxdLogger() ctxd.Logger

CtxdLogger is a service provider.

func (Observer) Debug

func (o Observer) Debug(ctx context.Context, msg string, keysAndValues ...interface{})

Debug logs debug message.

func (Observer) Error

func (o Observer) Error(ctx context.Context, msg string, keysAndValues ...interface{})

Error logs an error.

func (Observer) Important

func (o Observer) Important(ctx context.Context, msg string, keysAndValues ...interface{})

Important logs important information.

func (Observer) Info

func (o Observer) Info(ctx context.Context, msg string, keysAndValues ...interface{})

Info logs informational message.

func (Observer) LevelObservers

func (o Observer) LevelObservers() []*logz.Observer

LevelObservers returns .

func (Observer) Warn

func (o Observer) Warn(ctx context.Context, msg string, keysAndValues ...interface{})

Warn logs a warning.

func (Observer) WithLogger added in v1.1.0

func (o Observer) WithLogger(l ctxd.Logger) Observer

WithLogger returns a copy of Observer with logger, level buckets remain the same.

Jump to

Keyboard shortcuts

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