Skip to content

A Go (Golang) plugin for filtering logs based on packages and file names

License

Notifications You must be signed in to change notification settings

torbensky/go-logfilter

Repository files navigation

go-logfilter

A Go (Golang) library for configuring log output levels at a package or file level.

Usage

Working example

func main(){
    gfl := logfilter.NewLogFilter()

    // Only log error or higher for a package
    glf.SetLevel(log.ErrorLevel, "github.com/my/package") 

    // Output debug or higher for a specific file. File matches are given priority over package matches.
    glf.SetLevel(log.DebugLevel, "github.com/my/package/file.go")

    // Load a bunch of filters from a config
    config := `
		file1.go:debug,
		file2.go:warn,
		github.com/torbensky/logfilter:panic
	`
    gfl = LoadConfig(config)

    // Wrap a logrus Hook with the filter
    hook := airbrake.NewHook(123, "xyz", "development")
    hook = logfilter.NewHookFilter(hook, gfl) // Now only the unfiltered entries will go to airbrake
}

About

A Go (Golang) plugin for filtering logs based on packages and file names

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages