Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/illarion/rotate4logrus
rotate hook for logrus
https://github.com/illarion/rotate4logrus
logrotate logrus rotate
Last synced: about 2 months ago
JSON representation
rotate hook for logrus
- Host: GitHub
- URL: https://github.com/illarion/rotate4logrus
- Owner: illarion
- License: mit
- Created: 2021-08-28T17:00:18.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-02-21T15:17:02.000Z (almost 2 years ago)
- Last Synced: 2024-06-21T07:36:42.561Z (7 months ago)
- Topics: logrotate, logrus, rotate
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rotate4logrus
Logrotate-like hook for [sirupsen/logrus](https://github.com/sirupsen/logrus)
It produces files in the following format:
```{bash}
rotating_log.txt
rotating_log.txt.0
rotating_log.txt.1
rotating_log.txt.2
rotating_log.txt.3
```When there are more than `Rotate` files, the oldest one is deleted,
and the rest are renamed to the next number, so
`rotating_log.txt.4` becomes `rotating_log.txt.3`,
`rotating_log.txt.3` becomes `rotating_log.txt.2`, and so on.Rotating is done when the file size exceeds `Size` bytes.
## Example
```{go}
var log = logrus.New()
log.Level = logrus.TraceLevel
log.Formatter = new(logrus.TextFormatter)
context := context.Background()hook, err := rotate4logrus.New(context, rotate4logrus.HookConfig{
Levels: logrus.AllLevels,
FilePath: "/tmp/rotating_log.txt",
Rotate: 5,
Size: 16000,
Mode: 0600,
})if err != nil {
t.Error(err)
}log.Hooks.Add(hook)
log.Info("Hello World!")
continueFn := hook.Pause()
log.Info("This line will never be rotated")
log.Info("So that during this time you can, for example, make a zip archive of the log file")
continueFn()
log.Info("This line could be rotated")
```# License
MIT. See LICENSE for more details