gologger

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2022 License: MIT Imports: 6 Imported by: 0

README

GOLogger Build Status Coverage Status GoDoc License

GOLogger A Simple logging package, prefixes logging level. Also supports error logging to bugsnag.

Currently supported middlewares:

Usage

Get the library:

$ go get -v github.com/illuminasy/gologger

Without Bugsnag

func startApp() {
	err := doSomething()
	gologger.LogIfErr(err)
}

With Bugsnag There are 2 ways to use this package with bugsnag

  1. With gorouter package, which has a middleware which does error reporting to external service checkout https://github.com/illuminasy/gorouter for more info and configuration. No need to reconfigure bugsnag here

  2. With out gorouter package, you will need to configure bugsnag here to make it work

  3. With gorouter package

func startApp() {
	errTest = errors.New("test error class")
	lc := gologger.Config{
		Bugsnag: true,
		CustomErrorClass: map[string]error{
			"ErrTest": errTest,
		},
	}
	gologger.Configure(lc)

	// Wrap error with custom error for grouping by error class in Bugsnag
	err := gologger.Wrap(errTest, fmt.Errorf("Error something should not have happened"))
	gologger.Error(err)
}

  1. Without gorouter package
func startApp() {
	bc := gologger.BugsnagConfig {
		APIKey:              "testing",
		ReleaseStage:        "Dev",
		AppType:             "logger",
		AppVersion:          "0.1.0",
		ProjectPackages:     []string{
			"main",
		},
		NotifyReleaseStages: []string{
			"Dev",
		},
		ParamsFilters:       []string{"password", "secret"},
		PanicHandler:        func() {},
		Hostname:            "localhost",
	}
	gologger.ConfigureBugsnag(bc)

	errTest = errors.New("test error class")
	lc := gologger.Config{
		Bugsnag: true,
		CustomErrorClass: map[string]error{
			"ErrTest": errTest,
		},
	}
	gologger.Configure(lc)

	// Wrap error with custom error for grouping by error class in Bugsnag
	err := gologger.Wrap(errTest, fmt.Errorf("Error something should not have happened"))
	gologger.Error(err)
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(config Config)

Configure Configure gologger

func ConfigureBugsnag added in v0.1.4

func ConfigureBugsnag(config BugsnagConfig)

ConfigureBugsnag Configure bugsnag

func Error

func Error(err error, a ...interface{})

Error Logs an Error

func Fatal added in v0.1.4

func Fatal(err error, a ...interface{})

Fatal Logs an Fatal

func Info

func Info(message interface{}, a ...interface{})

Info Logs an info

func LogIfErr

func LogIfErr(err error)

LogIfErr Log only if there is an error

func Warn

func Warn(err error, a ...interface{})

Warn Logs a warning

func WarnIfErr

func WarnIfErr(err error)

WarnIfErr Warn only if there is an error

func Wrap

func Wrap(err1 error, err2 error) error

Wrap wraps error with custom error so we can group them by error class in bugsnag

Example (Output)
errTest = errors.New("test error class")
lc := Config{
	CustomErrorClass: map[string]error{
		"ErrTest": errTest,
	},
}
Configure(lc)

err := Wrap(errTest, fmt.Errorf("Error something should not have happened"))
fmt.Println(err.Error())
Output:

Error something should not have happened: test error class

Types

type BugsnagConfig added in v0.1.4

type BugsnagConfig struct {
	APIKey              string
	ReleaseStage        string
	AppType             string
	AppVersion          string
	ProjectPackages     []string
	NotifyReleaseStages []string
	ParamsFilters       []string
	PanicHandler        func()
	Hostname            string
}

BugsnagConfig Bugsnag Configuration

type Config

type Config struct {
	Bugsnag          bool
	CustomErrorClass map[string]error
}

Config Go logger config struct CustomErrorClass mapping errors to string, used in bugsnag to group by Requires manually setting group classes in bugsnag website

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL