logging

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 7 Imported by: 19

Documentation

Overview

Package logging record log with zap and sentry without complex config

use SetConfig before first Logger call, default to zap.NewDevelopmentConfig.

call Sync before program exit, it will call Sync method for underlying zap cores.

Index

Constants

This section is empty.

Variables

View Source
var ConsoleLevel = zapcore.InfoLevel

ConsoleLevel for console log.

logger that name is DebugLoggerName will be debug level.

View Source
var DebugLoggerName = os.Getenv("DEBUG")

DebugLoggerName specify console debug logger by name.

View Source
var (
	// HubContextKey used to store logging hub
	HubContextKey = &contextKey{}
)
View Source
var SentryLevel = zapcore.WarnLevel

SentryLevel for sentry log.

Functions

func Logger

func Logger(n string) *zap.Logger

Logger returns named logger from background hub

func SetConfig

func SetConfig(config zap.Config) error

SetConfig apply zap config.

config level is ignored, change ConsoleLevel, SentryLevel and DebugLoggerName before SetConfig to specify log level.

func Sync

func Sync() error

Sync all used zap cores, call this before program exit.

Types

type Hub

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

Hub for zap and sentry

func For

func For(ctx context.Context) *Hub

For returns hub for given context, will use background hub if not set on context or context is nil.

Use `With` if you are going modify sentry scope, so they don't mixed up between goroutine.

func With

func With(ctx context.Context) (context.Context, *Hub)

With attach new hub to context, use a clone of context or current sentry hub.

Use `For` if you are not going to modify sentry scope, so we can reuse cached logger.

func (*Hub) Logger

func (h *Hub) Logger(n string) *zap.Logger

Logger returns a named logger that level based on ConsoleLevel, SentryLevel and DebugLoggerName .

Jump to

Keyboard shortcuts

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