Simple yet powerful logrus hook for aliyun simple logging service.
- Batch sending logs asynchronously
- Dump huge logs (exceeds sls service limit) to stdout
- Fallback dumping logs to stdout when sls api not available
Simply add a hook to global logrus instance or any logrus instance.
slsLogrusHook, err := hook.NewSlsLogrusHook("<project>.<region>.log.aliyuncs.com", "access_key", "access_secret", "logstore", "topic")
logrus.AddHook(slsLogrusHook)
Ensure logs are flushed to sls before program exits
slsLogrusHook.Flush(5 * time.Second)
Disable processing logs for default output.
logrus.SetFormatter(&hook.NoopFormatter{})
logrus.SetOutput(ioutil.Discard)
Disable locks.
logrus.StandardLogger().SetNoLock()
Setting send interval if necessary.
slsLogrusHook.SetSendInterval(100 * time.Millisecond) // defaults to 300 * time.Millisecond
This project welcomes contributions from the community. Contributions are accepted using GitHub pull requests. If you're not familiar with making GitHub pull requests, please refer to the GitHub documentation "Creating a pull request".