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.
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
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.
MIT, see LICENSE.
"Use, abuse, have fun and contribute back!"
See contributing.md.