logger

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: MIT Imports: 5 Imported by: 5

Documentation

Overview

Package logger provides structured logging abstraction or facade, to be used by code which is not aware what logging library is used by end user.

Each message logged has a level, which was modeled after http://tools.ietf.org/html/rfc5424 severity levels:

  • Debug - Information useful to developers for debugging the application.
  • Info - Normal operational messages that require no action.
  • Warn - May indicate that an error will occur if action is not taken.
  • Error - Non-urgent failures - these should be relayed to developers or admins; each item must be resolved within a given time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	Log(context.Context, Entry)
}

Adapter is an interface to be implemented by logger adapters.

type Entry

type Entry struct {
	Level   Level
	Message string
	Fields  []Field // Fields can be nil
	Error   error   // Error can be nil
	// SkippedCallerFrames can be used by logger.Adapter to extract caller information (file and line number)
	SkippedCallerFrames int
}

func (Entry) With

func (e Entry) With(field Field) Entry

With creates a new entry with additional field.

type Field

type Field struct {
	Key   string
	Value interface{}
}

type Global

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

Global is a logger shared globally. You can use it to define global logger for your package:

package yourpackage
import "github.com/elgopher/yala/logger"
var Logger logger.Global // define global logger, no need to initialize (by default nothing is logged)

It is safe to use it concurrently.

func (*Global) Debug

func (g *Global) Debug(ctx context.Context, msg string)

Debug logs message using globally configured logger.Adapter.

func (*Global) Error

func (g *Global) Error(ctx context.Context, msg string)

Error logs message using globally configured logger.Adapter.

func (*Global) Info

func (g *Global) Info(ctx context.Context, msg string)

Info logs message using globally configured logger.Adapter.

func (*Global) SetAdapter

func (g *Global) SetAdapter(adapter Adapter)

SetAdapter updates adapter implementation. By default, nothing is logged.

It can be run anytime. Please note though that this method is meant to be used by end user, configuring logging from the central place (such as main.go or any other package setting up the entire application).

func (*Global) Warn

func (g *Global) Warn(ctx context.Context, msg string)

Warn logs message using globally configured logger.Adapter.

func (*Global) With

func (g *Global) With(ctx context.Context, key string, value interface{}) Logger

With creates a new Logger with field and using globally configured logger.Adapter.

func (*Global) WithError

func (g *Global) WithError(ctx context.Context, err error) Logger

WithError creates a new Logger with error and using globally configured logger.Adapter.

type Level

type Level string
const (
	DebugLevel Level = "DEBUG"
	InfoLevel  Level = "INFO"
	WarnLevel  Level = "WARN"
	ErrorLevel Level = "ERROR"
)

type Local

type Local struct {
	Adapter Adapter
}

Local is an immutable struct to log messages or create new loggers with fields or error.

It is safe to use it concurrently.

func (Local) Debug added in v0.12.0

func (l Local) Debug(ctx context.Context, msg string)

func (Local) Error added in v0.12.0

func (l Local) Error(ctx context.Context, msg string)

func (Local) Info added in v0.12.0

func (l Local) Info(ctx context.Context, msg string)

func (Local) Warn added in v0.12.0

func (l Local) Warn(ctx context.Context, msg string)

func (Local) With added in v0.12.0

func (l Local) With(ctx context.Context, key string, value interface{}) Logger

With creates a new Logger with field.

func (Local) WithError added in v0.12.0

func (l Local) WithError(ctx context.Context, err error) Logger

WithError creates a new Logger with error.

func (Local) WithSkippedCallerFrame added in v0.12.0

func (l Local) WithSkippedCallerFrame(ctx context.Context) Logger

type Logger

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

Logger is an immutable struct to log messages or create new loggers with fields or error.

It is safe to use it concurrently.

func (Logger) Debug

func (l Logger) Debug(msg string)

func (Logger) Error

func (l Logger) Error(msg string)

func (Logger) Info

func (l Logger) Info(msg string)

func (Logger) Warn

func (l Logger) Warn(msg string)

func (Logger) With

func (l Logger) With(key string, value interface{}) Logger

With creates a new Logger with field.

func (Logger) WithError

func (l Logger) WithError(err error) Logger

WithError creates a new Logger with error.

func (Logger) WithSkippedCallerFrame

func (l Logger) WithSkippedCallerFrame() Logger

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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