No description
Find a file
kpcraig ac8b318eab
Merge pull request #16 from hashicorp/compliance/update-headers
[IND-4227] [COMPLIANCE] Update Copyright Headers
2026-01-23 11:05:12 -05:00
.github [Compliance] - PR Template Changes Required 2025-07-03 09:51:47 +00:00
.gitignore Initial commit 2013-10-09 00:31:15 -07:00
CODEOWNERS Create CODEOWNERS 2024-11-26 12:52:31 -05:00
go.mod Add go.mod 2018-08-28 11:52:11 -04:00
level.go Remove exec permission from .go files. 2015-03-24 07:01:26 +01:00
level_benchmark_test.go fmt 2013-10-09 21:58:32 -10:00
level_test.go Remove exec permission from .go files. 2015-03-24 07:01:26 +01:00
LICENSE [COMPLIANCE] Update Copyright and License Headers 2025-12-09 11:18:33 +00:00
README.md Fix README example 2015-06-09 00:04:31 -07:00

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.