https://github.com/innopals/sls-logrus-hook
Logrus hook for aliyun sls
https://github.com/innopals/sls-logrus-hook
aliyun aliyun-sls golang logging logrus logrus-hook
Last synced: 3 months ago
JSON representation
Logrus hook for aliyun sls
- Host: GitHub
- URL: https://github.com/innopals/sls-logrus-hook
- Owner: innopals
- License: mit
- Created: 2019-05-28T04:22:30.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-04-01T03:47:16.000Z (about 4 years ago)
- Last Synced: 2025-08-21T11:04:03.582Z (10 months ago)
- Topics: aliyun, aliyun-sls, golang, logging, logrus, logrus-hook
- Language: Go
- Size: 35.2 KB
- Stars: 25
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Logrus Hook for Aliyun SLS
[](https://travis-ci.org/innopals/sls-logrus-hook)
[](https://goreportcard.com/report/github.com/innopals/sls-logrus-hook)
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.
```golang
slsLogrusHook, err := hook.NewSlsLogrusHook("..log.aliyuncs.com", "access_key", "access_secret", "logstore", "topic")
logrus.AddHook(slsLogrusHook)
```
Ensure logs are flushed to sls before program exits
```golang
slsLogrusHook.Flush(5 * time.Second)
```
## Performance Tuning
Disable processing logs for default output.
```golang
logrus.SetFormatter(&hook.NoopFormatter{})
logrus.SetOutput(ioutil.Discard)
```
Disable locks.
```golang
logrus.StandardLogger().SetNoLock()
```
Setting send interval if necessary.
```golang
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"](https://help.github.com/articles/creating-a-pull-request/).