logr

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

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.

Documentation

Overview

Example
package main

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()
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Caller

func Caller(depth int) (string, string, uint)

Caller returns the filename and line number of the function at the specified depth up the callstack

func CallerPackageName

func CallerPackageName(depth int) string

CallerPackageName returns the name of the go package of the function at specified depth up the callstack

func Debug

func Debug(v ...any)

func Debugf

func Debugf(format string, v ...any)

func Error

func Error(v ...any)

func Errorf

func Errorf(format string, v ...any)

func Fatal

func Fatal(v ...any)

func Fatalf

func Fatalf(format string, v ...any)

func Info

func Info(v ...any)

func Infof

func Infof(format string, v ...any)

func RSplitN

func RSplitN(s, sep string, n int) []string

RSplitN like SplitN but starting from the right

func Trace added in v0.2.0

func Trace(v ...any)

func Tracef added in v0.2.0

func Tracef(format string, v ...any)

func Warn

func Warn(v ...any)

func Warnf

func Warnf(format string, v ...any)

func Warning

func Warning(v ...any)

func Warningf

func Warningf(format string, v ...any)

Types

This section is empty.

Directories

Path Synopsis
fmt

Jump to

Keyboard shortcuts

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