sls-logrus-hook
sls-logrus-hook copied to clipboard
Logrus hook for aliyun sls
Logrus Hook for Aliyun SLS
Simple yet powerful logrus hook for aliyun simple logging service.
Features
- Batch sending logs asynchronously
- Dump huge logs (exceeds sls service limit) to stdout
- Fallback dumping logs to stdout when sls api not available
Getting Start
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)
Performance Tuning
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
Contributing
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".