log

package module
v0.0.0-...-efdd7b7 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: Apache-2.0 Imports: 3 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Log

Logrus is a structured logger for Go (golang), completely API compatible with the standard library logger.

With log.SetFormatter(&log.JSONFormatter{}), for easy parsing by logstash or Splunk:

{"animal":"walrus","level":"info","msg":"A group of walrus emerges from the
ocean","size":10,"time":"2014-03-10 19:57:38.562264131 -0400 EDT"}

{"level":"warning","msg":"The group's number increased tremendously!",
"number":122,"omg":true,"time":"2014-03-10 19:57:38.562471297 -0400 EDT"}

{"animal":"walrus","level":"info","msg":"A giant walrus appears!",
"size":10,"time":"2014-03-10 19:57:38.562500591 -0400 EDT"}

{"animal":"walrus","level":"info","msg":"Tremendously sized cow enters the ocean.",
"size":9,"time":"2014-03-10 19:57:38.562527896 -0400 EDT"}

{"level":"fatal","msg":"The ice breaks!","number":100,"omg":true,
"time":"2014-03-10 19:57:38.562543128 -0400 EDT"}

Install

go get github.com/deepauto-io/log

Example

s.Logger.
	WithField("error", err.Error()).
	WithField("url", src.URL).
	Info("Failed to retrieve database version")

Logger as an io.Writer

w := logger.Writer()
defer w.Close()

srv := http.Server{
    // create a stdlib log.Logger that writes to
    // logrus.Logger.
    ErrorLog: log.New(w, "", 0),
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level uint8

Level type

const (
	// PanicLevel level, the 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
)

These are the different logging levels.

func ParseLevel

func ParseLevel(lvl string) Level

ParseLevel takes a string level and returns the Logrus log level constant.

type Logger

type Logger interface {
	Debug(...interface{})
	Info(...interface{})
	Error(...interface{})
	Warn(...interface{})

	WithField(string, interface{}) Logger

	// Writer Logger can be transformed into an io.Writer.
	// That writer is the end of an io.Pipe and it is your responsibility to close it.
	Writer() *io.PipeWriter
}

Logger represents an abstracted structured logging implementation. It provides methods to trigger log messages at various alert levels and a WithField method to set keys for a structured log message.

func New

func New(l Level) Logger

New wraps a logrus Logger

func NewJ

func NewJ(l Level) Logger

NewJ wraps a logrus Logger

func NewJNop

func NewJNop() Logger

NewJNop wraps a default logrus Logger

func NewNop

func NewNop() Logger

NewNop wraps a default logrus Logger

Jump to

Keyboard shortcuts

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