log

package
v0.0.0-...-93b1e75 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package log provides simple logger designed to write info messages into stdout, and error messages into stderr. It uses zap sugared logger undercover but with very simple API that is enough in almost all situations.

Typical usage:

logger := log.MustNew(log.WithName("my-logger"), log.WithDebug(true))
logger.Debug("Some debug message")
logger.Info("Some info message")
logger.Error("Some error message")
logger.Sync()

Name is optional but highly recommended if you have more than one logger in your application to distinguish them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

Config structure with logger configuration. Shouldn't be created manually.

type ConfigService

type ConfigService interface {
	GetByKey(string, interface{}) error
	IsNoSuchKeyError(error) bool
}

ConfigService interface used to obtain configuration from somewhere into some specific structure.

type Logger

type Logger interface {
	Debug(msg string, v ...interface{})
	Info(msg string, v ...interface{})
	Error(msg string, v ...interface{})
	Fatal(msg string, v ...interface{})
	Sync()
}

Logger interface.

type Option

type Option func(*Config) error

Option function that is fed to New and MustNew. Obtain them using 'With' functions down below.

func WithConfig

func WithConfig(service ConfigService, key string) Option

WithConfig option retrieves configuration from provided configuration service.

Example JSON configuration with all possible fields (if some are not present, defaults will be used):

{
    "name": "logger-name",
    "debug": true
}

func WithDebug

func WithDebug(debug bool) Option

WithDebug option sets debug mode. Default: false.

func WithName

func WithName(name string) Option

WithName option applies provided logger name.

func WithStderr

func WithStderr(stderr zapcore.WriteSyncer) Option

WithStderr option applies customized stderr, usually for testing.

func WithStdout

func WithStdout(stdout zapcore.WriteSyncer) Option

WithStdout option applies customized stdout, usually for testing.

type StandardLogger

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

StandardLogger which uses standard logging format and implements Logger interface.

func MustNew

func MustNew(opts ...Option) *StandardLogger

MustNew function creates new standard logger with provided options and panics on any error.

func New

func New(opts ...Option) (*StandardLogger, error)

New function creates new standard logger with provided options.

func NewNop

func NewNop() *StandardLogger

NewNop function creates dummy logger that produces no output at all.

func (*StandardLogger) Debug

func (logger *StandardLogger) Debug(msg string, v ...interface{})

Debug method writes debug message into log.

func (*StandardLogger) Error

func (logger *StandardLogger) Error(msg string, v ...interface{})

Error method writes error message into log.

func (*StandardLogger) Fatal

func (logger *StandardLogger) Fatal(msg string, v ...interface{})

Fatal method writes fatal message into log, then calls panic.

func (*StandardLogger) Info

func (logger *StandardLogger) Info(msg string, v ...interface{})

Info method writes info message into log.

func (*StandardLogger) Sync

func (logger *StandardLogger) Sync()

Sync method synchronizes logger io.

Jump to

Keyboard shortcuts

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