log

package module
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2021 License: MIT Imports: 11 Imported by: 10

README

logs-go

CircleCI codecov

Wrapper for zerolog tuned to work with configuration and sentry hook.

Usage

Initiate new logger with filled log.Config and use it as common zerolog

package main

import (
	log "github.com/spacetab-io/logs-go/v2"
)

func main() {
	conf := log.Config{
		Level:  "warn",
		Format: "text",
		Caller: &log.CallerConfig{
			Disabled:         false,
			CallerSkipFrames: 2,
		},
		Sentry: &log.SentryConfig{
			Enable: true,
			DSN:    "http://dsn.sentry.com",
		},
	}

	if err := log.Init("test", conf, "logs-go", "v2.*.*", nil); err != nil {
		panic(err)
	}

	log.Warn().Msg("log some warning")
}

Licence

The software is provided under MIT Licence.

Documentation

Overview

Package log provides a global logger for zerolog.

Index

Constants

View Source
const (
	FormatText = "text"
	FormatJSON = "json"
)

Variables

This section is empty.

Functions

func Ctx

func Ctx(ctx context.Context) *zerolog.Logger

Ctx returns the logger associated with the ctx. If no logger is associated, a disabled logger is returned.

func Debug

func Debug() *zerolog.Event

Debug starts a new message with debug level.

You must call Msg on the returned event in order to send the event.

func Err

func Err(err error) *zerolog.Event

Err starts a new message with error level with err as a field if not nil or with info level if err is nil.

You must call Msg on the returned event in order to send the event.

func Error

func Error() *zerolog.Event

Error starts a new message with error level.

You must call Msg on the returned event in order to send the event.

func Fatal

func Fatal() *zerolog.Event

Fatal starts a new message with fatal level. The os.Exit(1) function is called by the Msg method.

You must call Msg on the returned event in order to send the event.

func Hook

func Hook(h zerolog.Hook) zerolog.Logger

Hook returns a logger with the h Hook.

func Info

func Info() *zerolog.Event

Info starts a new message with info level.

You must call Msg on the returned event in order to send the event.

func Init

func Init(stage string, cfg Config, serviceAlias string, serviceVersion string, w io.Writer) (err error)

set global Zerolog logger.

func Level

func Level(level zerolog.Level) zerolog.Logger

Level creates a child logger with the minimum accepted level set to level.

func LevelString added in v2.0.2

func LevelString(lvl string) zerolog.Logger

LevelString creates a child logger with the minimum accepted level set to level passed as string.

func Log

func Log() *zerolog.Event

Log starts a new message with no level. Setting zerolog.GlobalLevel to zerolog.Disabled will still disable events produced by this method.

You must call Msg on the returned event in order to send the event.

func Output

func Output(w io.Writer) zerolog.Logger

Output duplicates the global logger and sets w as its output.

func Panic

func Panic() *zerolog.Event

Panic starts a new message with panic level. The message is also sent to the panic function.

You must call Msg on the returned event in order to send the event.

func Print

func Print(v ...interface{})

Print sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Print.

func Printf

func Printf(format string, v ...interface{})

Printf sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Printf.

func Sample

func Sample(s zerolog.Sampler) zerolog.Logger

Sample returns a logger with the s sampler.

func Trace

func Trace() *zerolog.Event

Trace starts a new message with trace level.

You must call Msg on the returned event in order to send the event.

func Warn

func Warn() *zerolog.Event

Warn starts a new message with warn level.

You must call Msg on the returned event in order to send the event.

func With

func With() zerolog.Context

With creates a child logger with the field added to its context.

func WithCtx

func WithCtx(ctx context.Context) *zerolog.Logger

With creates a child logger with the field added to its context.

func WithLevel

func WithLevel(level zerolog.Level) *zerolog.Event

WithLevel starts a new message with level.

You must call Msg on the returned event in order to send the event.

Types

type CallerConfig added in v2.0.3

type CallerConfig struct {
	Disabled         bool `yaml:"hide_caller"`
	CallerSkipFrames int  `yaml:"skip_frames"`
}

type Config

type Config struct {
	Level   string        `yaml:"level"`
	Format  Format        `yaml:"format"`
	NoColor bool          `yaml:"no_color"`
	Caller  *CallerConfig `yaml:"caller"`
	Sentry  *SentryConfig `yaml:"sentry,omitempty"`
}

type FHLogger

type FHLogger struct{}

func (FHLogger) Printf

func (fhl FHLogger) Printf(format string, v ...interface{})

type Format

type Format string

type NSQLogger added in v2.0.2

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

func NewNSQLogger added in v2.0.2

func NewNSQLogger(logLevel string) NSQLogger

func (NSQLogger) LogLevel added in v2.0.4

func (nl NSQLogger) LogLevel() int

func (NSQLogger) Output added in v2.0.2

func (nl NSQLogger) Output(calldepth int, s string) error

type SentryConfig

type SentryConfig struct {
	DSN    string `yaml:"dsn"`
	Enable bool   `yaml:"enable"`
	Debug  bool   `yaml:"debug"`
}

type ZLogger added in v2.1.0

type ZLogger struct {
	zerolog.Logger
	// contains filtered or unexported fields
}

func Logger

func Logger() ZLogger

Jump to

Keyboard shortcuts

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