- Structured logging
- Supports AWS CloudWatch
- Simple interface for implementing your own
package main
import (
"fmt"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/gofor-little/log"
)
func main() {
// Standard logger writes to a user defined io.Writer.
log.Log = log.NewStandardLogger(os.Stdout, log.Fields{
"tag": "standard_logger",
})
// CloudWatch logger writes to an AWS CloudWatch log group.
sess, err = session.NewSession()
log.Log, err = log.NewCloudWatchLogger(context.Background(), os.Getenv("AWS_PROFILE"), os.Getenv("AWS_REGION"), "CloudWatchLoggerTest", log.Fields{
"tag": "cloudWatchLoggerTest",
})
if err != nil {
panic(err)
}
// Log at info, error and debug levels.
log.Info(log.Fields{
"message": "info message",
"bool": true,
"int": 64,
"float": 3.14159,
})
log.Error(log.Fields{
"string": "error message",
"bool": true,
"int": 64,
"float": 3.14159,
})
log.Debug(log.Fields{
"string": "debug message",
"bool": true,
"int": 64,
"float": 3.14159,
})
}
Ensure the following environment variables are set, usually with a .env file.
AWS_PROFILE
(an AWS CLI profile name)AWS_REGION
(a valid AWS region)
Run go test -v -race ./...
in the root directory.