terraform/vendor/github.com/hashicorp/logutils
Radek Simko e0841f73b3
vendor: github.com/hashicorp/logutils@v1.0.0
2019-02-12 10:25:04 +00:00
..
.gitignore vendor: update to latest github.com/zclconf/go-cty 2018-10-16 19:14:11 -07:00
LICENSE Vendor all dependencies w/ Godep 2016-01-29 15:08:48 -06:00
README.md Vendor all dependencies w/ Godep 2016-01-29 15:08:48 -06:00
go.mod vendor: github.com/hashicorp/logutils@v1.0.0 2019-02-12 10:25:04 +00:00
level.go Vendor all dependencies w/ Godep 2016-01-29 15:08:48 -06:00

README.md

logutils

logutils is a Go package that augments the standard library "log" package to make logging a bit more modern, without fragmenting the Go ecosystem with new logging packages.

The simplest thing that could possibly work

Presumably your application already uses the default log package. To switch, you'll want your code to look like the following:

package main

import (
	"log"
	"os"

	"github.com/hashicorp/logutils"
)

func main() {
	filter := &logutils.LevelFilter{
		Levels: []logutils.LogLevel{"DEBUG", "WARN", "ERROR"},
		MinLevel: logutils.LogLevel("WARN"),
		Writer: os.Stderr,
	}
	log.SetOutput(filter)

	log.Print("[DEBUG] Debugging") // this will not print
	log.Print("[WARN] Warning") // this will
	log.Print("[ERROR] Erring") // and so will this
	log.Print("Message I haven't updated") // and so will this
}

This logs to standard error exactly like go's standard logger. Any log messages you haven't converted to have a level will continue to print as before.