log

package module
Version: v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: MIT Imports: 3 Imported by: 8

README

log

A high-level API adapter for logrus.

Godoc Reference Go Report Card

Overview

Package log provides a high-level API adapter around logrus. It is intended as a personal utility. You are likely to prefer using Logrus directly.

This package makes the following changes to the logrus API:

  • Functional options for a more user-friendly API.
  • Adds Logger.With method, which applies log fields directly from objects satisfying Loggable.
  • Remove panic-level logging, as Panic and Fatal are semantically equivalent.

Escape hatches are provided to maintain full compatibility with Logrus.

Documentation

Overview

Package log contains an improved API and utilities for github.com/sirupsen/logrus

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

Debug prints a message at debug level.

func Debugf

func Debugf(fmt string, v ...interface{})

Debugf provides fmt.Printf-like formatting for a call to Trace

func Debugln

func Debugln(v ...interface{})

Debugln calls Trace, adding a newline to the log output.

func Error

func Error(v ...interface{})

Error prints a message at error level.

func Errorf

func Errorf(fmt string, v ...interface{})

Errorf provides fmt.Printf-like formatting for a call to Trace

func Errorln

func Errorln(v ...interface{})

Errorln calls Trace, adding a newline to the log output.

func Fatal

func Fatal(v ...interface{})

Fatal prints each value then calls os.Exit(1)

func Fatalf

func Fatalf(fmt string, v ...interface{})

Fatalf provides fmt.Printf-like formatting for a call to Fatal.

func Fatalln

func Fatalln(v ...interface{})

Fatalln calls Fatal, appending a newline to the log output.

func Info

func Info(v ...interface{})

Info prints a message at info level.

func Infof

func Infof(fmt string, v ...interface{})

Infof provides fmt.Printf-like formatting for a call to Trace

func Infoln

func Infoln(v ...interface{})

Infoln calls Trace, adding a newline to the log output.

func Trace

func Trace(v ...interface{})

Trace prints a message at trace level.

func Tracef

func Tracef(fmt string, v ...interface{})

Tracef provides fmt.Printf-like formatting for a call to Trace

func Traceln

func Traceln(v ...interface{})

Traceln calls Trace, adding a newline to the log output.

func Warn

func Warn(v ...interface{})

Warn prints a message at warn level.

func Warnf

func Warnf(fmt string, v ...interface{})

Warnf provides fmt.Printf-like formatting for a call to Trace

func Warnln

func Warnln(v ...interface{})

Warnln calls Trace, adding a newline to the log output.

Types

type F

type F map[string]interface{}

F is a set of fields

func (F) Loggable added in v1.2.0

func (f F) Loggable() map[string]interface{}

Loggable allows Logger.With to consume an F.

type Level

type Level uint8

Level .

const (
	// FatalLevel logs and then calls `os.Exit(1)`.
	FatalLevel Level = iota

	// ErrorLevel is used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel

	// WarnLevel is for non-critical entries that deserve eyes.
	WarnLevel

	// InfoLevel provides general operational entries about what's going on inside the
	// application.
	InfoLevel

	// DebugLevel is used to report application state for debugging perposes.
	DebugLevel

	// TraceLevel is used to trace the execution steps of an application for debugging
	// or optimization purposes.
	TraceLevel
)

type LevelHooks

type LevelHooks = logrus.LevelHooks

LevelHooks .

type Loggable

type Loggable interface {
	Loggable() map[string]interface{}
}

Loggable types provide a loggable representation of their internal state.

type Logger

type Logger interface {
	Fatal(...interface{})
	Fatalf(string, ...interface{})
	Fatalln(...interface{})

	Trace(...interface{})
	Tracef(string, ...interface{})
	Traceln(...interface{})

	Debug(...interface{})
	Debugf(string, ...interface{})
	Debugln(...interface{})

	Info(...interface{})
	Infof(string, ...interface{})
	Infoln(...interface{})

	Warn(...interface{})
	Warnf(string, ...interface{})
	Warnln(...interface{})

	Error(...interface{})
	Errorf(string, ...interface{})
	Errorln(...interface{})

	With(Loggable) Logger
	WithError(error) Logger
	WithField(string, interface{}) Logger
	WithFields(logrus.Fields) Logger
}

Logger provides observability

func New

func New(opt ...Option) Logger

New logger

func WrapLogrus

func WrapLogrus(l logrus.Ext1FieldLogger) Logger

WrapLogrus is a convenience function

type Option

type Option func(*logrus.Logger)

Option for Logger

func WithFormatter

func WithFormatter(f logrus.Formatter) Option

WithFormatter sets the formatter

func WithLevel

func WithLevel(l Level) Option

WithLevel sets the log level

func WithLevelHooks

func WithLevelHooks(hs LevelHooks) Option

WithLevelHooks sets the level hooks

func WithWriter

func WithWriter(w io.Writer) Option

WithWriter writer

Directories

Path Synopsis
Package doctest contains utilities for mocking logs in unit tests.
Package doctest contains utilities for mocking logs in unit tests.
util
zap
Package zaputil contains utilities for working with go.uber.org/zap.
Package zaputil contains utilities for working with go.uber.org/zap.

Jump to

Keyboard shortcuts

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