/logger

Logger provides standard logging methods around the standard log package.

Primary LanguageGoMIT LicenseMIT

Logger Build Status codecov Go Report Card GoDoc

Package logger provides standard logging methods around the standard log package. Each logged line is prefixed with the logging level (Debug, Info, Warn, ...). The Enabled and Level configurations are respected every time the logging methods are called. Logger provides a Logger interface for easy mocking and also an OnLog handler to help identify logged data in unit tests.

Install

From a configured Go environment:

go get -u github.com/cloud-spin/logger

If you are using dep:

dep ensure -add github.com/cloud-spin/logger

How to Use

Below example starts a enabled logger to Info level and logs a Info message with one parameter.

package main

import (
	"fmt"

	"github.com/cloud-spin/logger"
)

func main() {
	configs := &logger.Configs{
		Enabled: true,
		Level:   logger.LevelInfo,
	}
	logger, err := logger.New(configs)
	if err != nil {
		fmt.Printf("Expected: logger initialized; Got: %s", err.Error())
	}

	logger.Info("Info message with '%s' param", "string")
}

Output:

[INFO] 2018/09/10 11:20:11 Info message with 'string' param

Also refer to the tests at logger_test.go.

License

MIT, see LICENSE.

"Use, abuse, have fun and contribute back!"

Contributions

See contributing.md.