Git Product home page Git Product logo

logr's Introduction

logr

Godoc Reference

Reasonable logging facilities for Go

Simple interface with Time-Thread-Condition-Component based output, with automatic colored output if supported.

Features

  • Time: ISO 8901 format timestamps in UTC
  • Thread: Log source Goroutine identifiers
  • Condition: Log level based logging [TRACE, DEBUG, INFO, WARN, ERROR]
  • Component: Go module/package name
  • Colors: Automatically detects support for ANSI terminal colorization
  • Level Filtering: set a global level and/or per module levels
  • Configurable Ouput: use the built in JSON output, or make your own

Example

import (
	"sync"

	log "github.com/mrodden/logr"
	"github.com/mrodden/logr/env_logger"
)

func main() {
	env_logger.Init()

	log.Info("Hello Logging")

	log.Debug("Debug message output")

	wg := sync.WaitGroup{}
	wg.Add(1)
	go func() {
		log.Warn("Warning from inside a goroutine")
		wg.Done()
	}()

	log.Infof("Info format: %#v", wg)

	wg.Wait()
}

Colored output

Configuration

The default logging implementation is env_logger which can be configured with the GO_LOG environment variable.

Both the global logging level filter and per module declarations can be declared. The format is similar to the Rust env_logger crate.

Some examples:

  • GO_LOG=warn - Sets the global filter level to WARN, causing any logs of WARN, ERROR, or lower to be emitted from all modules.
  • GO_LOG=warn,github.com/mymodule/myapp=trace - Sets the global level to WARN, and the filter for the github.com/mymodule/myapp to TRACE level
  • GO_LOG=warn,main - Sets the global level to WARN, and enables all logging for the main module.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.