log

package
v0.0.0-...-8ffd910 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2020 License: MIT Imports: 10 Imported by: 0

README

log

import "github.com/srelab/common/log"

Overview

Package log wraps logrus to include source line/function information

Index

Package files

doc.go log.go

func Debug

func Debug(args ...interface{})

Debug logs a message at level Debug on the standard logger.

func Debugln

func Debugln(args ...interface{})

Debugln logs a message at level Debug on the standard logger.

func Error

func Error(args ...interface{})

Error logs a message at level Error on the standard logger.

func Errorln

func Errorln(args ...interface{})

Errorln logs a message at level Error on the standard logger.

func Fatal

func Fatal(args ...interface{})

Fatal logs a message at level Fatal on the standard logger.

func Fatalln

func Fatalln(args ...interface{})

Fatalln logs a message at level Fatal on the standard logger.

func Info

func Info(args ...interface{})

Info logs a message at level Info on the standard logger.

func Infoln

func Infoln(args ...interface{})

Infoln logs a message at level Info on the standard logger.

func SetLevel

func SetLevel(level Level)

SetLevel sets the Level of the base logger

func Warn

func Warn(args ...interface{})

Warn logs a message at level Warn on the standard logger.

func Warnln

func Warnln(args ...interface{})

Warnln logs a message at level Warn on the standard logger.

type Level

type Level uint8

Level describes the log severity level.

const (
    // PanicLevel level, highest level of severity. Logs and then calls panic with the
    // message passed to Debug, Info, ...
    PanicLevel Level = iota
    // FatalLevel level. Logs and then calls `os.Exit(1)`. It will exit even if the
    // logging level is set to Panic.
    FatalLevel
    // ErrorLevel level. Logs. Used for errors that should definitely be noted.
    // Commonly used for hooks to send errors to an error tracking service.
    ErrorLevel
    // WarnLevel level. Non-critical entries that deserve eyes.
    WarnLevel
    // InfoLevel level. General operational entries about what's going on inside the
    // application.
    InfoLevel
    // DebugLevel level. Usually only enabled when debugging. Very verbose logging.
    DebugLevel
)

type Logger

type Logger interface {
    SetLevel(level Level)
    SetOut(out io.Writer)

    Debug(...interface{})
    Debugln(...interface{})

    Info(...interface{})
    Infoln(...interface{})

    Warn(...interface{})
    Warnln(...interface{})

    Error(...interface{})
    Errorln(...interface{})

    Fatal(...interface{})
    Fatalln(...interface{})

    With(key string, value interface{}) Logger
    WithError(err error) Logger
}

Logger is an interface that describes logging.

func Base
func Base() Logger

Base returns the base logger.

func New
func New() Logger

New returns a new logger.

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

With attaches a key,value pair to a logger.

func WithError
func WithError(err error) Logger

WithError returns a Logger that will print an error along with the next message.

Documentation

Overview

Package log wraps logrus to include source line/function information

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

func Debugf

func Debugf(format string, args ...interface{})

func Debugln

func Debugln(args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Errorln

func Errorln(args ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func Fatalln

func Fatalln(args ...interface{})

func Info

func Info(args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func Infoln

func Infoln(args ...interface{})

func Init

func Init(config Config)

Initialize the logger with config When path is not legal, the current path will be used. Multiwriter by default

func Panic

func Panic(args ...interface{})

func Panicf

func Panicf(format string, args ...interface{})

func Panicln

func Panicln(args ...interface{})

func Print

func Print(args ...interface{})

func Printf

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

func Println

func Println(args ...interface{})

func SetLevel

func SetLevel(level Level)

SetLevel sets the Level of the base logger

func SetOut

func SetOut(out io.Writer)

SetOut sets the output destination base logger

func Trace

func Trace(args ...interface{})

func Tracef

func Tracef(format string, args ...interface{})

func Traceln

func Traceln(args ...interface{})

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

func Warnln

func Warnln(args ...interface{})

Types

type Config

type Config struct {
	File  string `yaml:"File"`
	Level string `yaml:"Level"`
}

type Level

type Level uint8

Level describes the log severity level.

const (
	// PanicLevel level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	PanicLevel Level = iota
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	FatalLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel
)

These are the different logging levels. You can set the logging level to log on your instance of logger, obtained with `logrus.New()`.

func GetLevel

func GetLevel() Level

GetLevel gets the level of a logger.

type Logger

type Logger interface {
	With(key string, value interface{}) Logger
	WithError(err error) Logger

	SetLevel(level Level)
	SetOut(out io.Writer)

	Trace(...interface{})
	Debug(...interface{})
	Print(...interface{})
	Info(...interface{})
	Warn(...interface{})
	Error(...interface{})
	Fatal(...interface{})
	Panic(...interface{})

	Tracef(string, ...interface{})
	Debugf(string, ...interface{})
	Printf(string, ...interface{})
	Infof(string, ...interface{})
	Warnf(string, ...interface{})
	Errorf(string, ...interface{})
	Fatalf(string, ...interface{})
	Panicf(string, ...interface{})

	Traceln(...interface{})
	Debugln(...interface{})
	Println(...interface{})
	Infoln(...interface{})
	Warnln(...interface{})
	Errorln(...interface{})
	Fatalln(...interface{})
	Panicln(...interface{})
}

Logger is an interface that describes logging.

func Base

func Base() Logger

Base returns the base logger.

func New

func New() Logger

New returns a new logger.

func With

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

func WithError

func WithError(err error) Logger

Jump to

Keyboard shortcuts

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