https://github.com/nir0s/logrotated
A human friendly interface to logrotate
https://github.com/nir0s/logrotated
Last synced: 8 months ago
JSON representation
A human friendly interface to logrotate
- Host: GitHub
- URL: https://github.com/nir0s/logrotated
- Owner: nir0s
- License: apache-2.0
- Created: 2016-04-30T15:13:27.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2021-03-19T21:28:52.000Z (over 5 years ago)
- Last Synced: 2025-09-06T13:44:15.639Z (10 months ago)
- Language: Python
- Size: 42 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- License: LICENSE
Awesome Lists containing this project
README
logrotated
==========
[](https://travis-ci.org/nir0s/logrotated)
[](http://img.shields.io/pypi/dm/logrotated.svg)
[](http://img.shields.io/pypi/v/logrotated.svg)
Why does your volume keep exploding? It's not ISIS! It's your logs!
`logrotated` is a CLI and Pythonic API for `logrotate` and `LogRotateWin` (SOON!). It aims to make logrotation easier without having to know the ins and outs of `logrotate`.
## Features
## Compatibility
Currently, tested on Python 2.6.x and 2.7.x
Will be adding Python 3.x support soon enough.
## Installation
```shell
sudo pip install logrotated
```
For dev:
```shell
sudo pip install https://github.com/nir0s/logrotated/archive/master.tar.gz
```
## Usage
```shell
$ sudo rotatethis --help
Usage: rotatethis [OPTIONS] PATH...
Generates a logrotate configuration and deploys it if necessary.
Options:
-n, --name TEXT The name of the logrotation script.
[required]
-d, --deploy Deploy the configuration on the current
machine.
-f, --frequency [daily|weekly|monthly|yearly]
How often to rotate the files.
-s, --size TEXT Size of file at which rotation will take
place. (e.g. 100k, 100M, 100G)
-k, --keep TEXT How many files to keep when rotating.
-c, --compress Whether to compress rotated log files or
not.
--create TEXT... Created new log files using `mod user
password`.
-l, --delay-compression TEXT Delay the compression by one file. This will
leave one rotated log file uncompressed
until the next rotation.
--nocompress Negates --compress (in case it is configured
in the main logrotate config.
--dont-rotate-empty Do not rotate empty files.
-m, --ignore-missing If there are no logs, don't fail.. just
continue.
--shared-postscript Run postrotate script only after all logs in
path have been checked.
-p, --post-rotate TEXT A script to run post rotation. This is
required by some applications.
--overwrite Whether to overwrite a logrotate config or
not.
-v, --verbose
--help Show this message and exit.
...
```
## Rotating Paths
```shell
$ rotatethis '/var/log/mongodb/*.log' '/var/log/mongos' --name mongo -v -p '/usr/bin/killall -SIGUSR1 mongod' -p '/usr/bin/killall -SIGUSR1 mongos' --keep 5 --frequency daily --create 644 user group --dont-rotate-empty --deploy
...
INFO - Generating logrotate config...
INFO - Deploying /tmp/logrotate-test/test to /etc/logrotate.d/test...
INFO - Deployment successful!
...
$ cat /etc/logrotate.d/mongo
/var/log/mongodb/*.log /var/log/mongos {
daily
rotate 5
notifempty
compress
create 644 user group
postrotate
/usr/bin/killall -SIGUSR1 mongod
/usr/bin/killall -SIGUSR1 mongos
endscript
}
```
### Generating only
If the `--deploy` flag isn't provided, the file will be saved under /tmp/logrotate-NAME/NAME for future use.
## Python API
```python
raise NotImplementedError()
```
## Testing
```shell
git clone git@github.com:nir0s/logrotated.git
cd logrotated
pip install tox
tox
```
## Contributions..
Pull requests are always welcome.