Categorygithub.com/sourcenetwork/corelog
repositorypackage
0.0.8
Repository: https://github.com/sourcenetwork/corelog.git
Documentation: pkg.go.dev

# README

Corelog

Logging library used across Source Network projects.

Usage

package main

import "github.com/sourcenetwork/corelog"

var log = corelog.NewLogger("main")

func main() {
    // with attributes
    log.Info("message", corelog.String("key", "val"))

    // with context
    log.InfoContext(ctx, "message", corelog.Int("key", 10))

    // with error stacktrace
    log.ErrorE("message", err, corelog.Bool("key", true))

    // with common attributes
    attrs := log.WithAttrs(corelog.Float64("key", float64(1.234)))
    attrs.Info("message")

    // with common group
    group := log.WithGroup("group")
    group.Info("message", corelog.Any("key", struct{}{}))
}

Configuration

Default config values can be set via environment variables.

EnvDescriptionValues
LOG_LEVELsets logging levelinfo error
LOG_FORMATsets logging formatjson text
LOG_STACKTRACEenables stacktracestrue false
LOG_SOURCEenables source locationtrue false
LOG_OUTPUTsets the output pathstderr stdout
LOG_OVERRIDESlogger specific overridesnet,level=info;core,output=stdout
LOG_NO_COLORdisable color text outputtrue false