logutils

Utilities for slightly better logging in Go (Golang).

  • 所有者: hashicorp/logutils
  • 平台:
  • 许可证: Mozilla Public License 2.0
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

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.

主要指标

概览
名称与所有者hashicorp/logutils
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证Mozilla Public License 2.0
所有者活动
创建于2013-10-09 07:31:15
推送于2024-12-02 16:04:37
最后一次提交2024-11-26 12:52:31
发布数1
最新版本名称v1.0.0 (发布于 )
第一版名称v1.0.0 (发布于 )
用户参与
星数367
关注者数303
派生数34
提交数24
已启用问题?
问题数5
打开的问题数1
拉请求数5
打开的拉请求数3
关闭的拉请求数1
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?