logger

package module
v0.0.0-...-87072a6 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

logger

Wrapper for go.uber.org/zap with Elastic Common Schema (ECS) default format.

Installation

go get -u github.com/bbraunstein/logger

Usage

import github.com/bbraunstein/logger

Quick Start

In contexts where performance is nice, but not critical, use the SugaredLogger. It is 4-10x faster than other structured logging packages and includes both structured and printf-style APIs.

log := logger.NewWithSugaredLogger()
defer log.Sync() // flushes buffer, in any
log.Infow("Failed to fetch URL",
    // Structured context as loosely typed key-value pairs.
    "url", url,
    "attempt", 3,
    "backoff", time.Second,
)
log.Infof("Failed to fetch URL: %s", url)

When performance and type safety are critical, use the Logger. Its even faster than the SugaredLogger and allocates far less, but only supports structured logging.

log := logger.New()
defer log.Sync()
log.Info("failed to fetch URL",
   // Structured context as strongly typed Field values.
   zap.String("url", url),
    zap.Int("attempt", 3),
    zap.Duration("backoff", time.Second),
)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() *zap.Logger

When performance and type safety are critical, use the `New`. It's even faster than the `SugaredLogger` and allocates far less, but it only supports structuted logging.

func NewWithSugaredLogger

func NewWithSugaredLogger() *zap.SugaredLogger

In contexts where performance is nice, but not critical, use the `SugaredLogger`. It is 4-10x faster than other structured logging packages and includes both structured and `printf`-style APIs.

Types

This section is empty.

Jump to

Keyboard shortcuts

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