napalm-logs
napalm-logs copied to clipboard
How to setup log rotation
Hi
I'm using napalm-logs 0.7.0 as a system service on CentOS 7. How should I setup a proper log rotation? Are there options to configure? What is the best practice solution?
Current config:
cat /usr/lib/systemd/system/napalm-logs.service
[Unit]
Description=napalm-logs
Documentation=https://napalm-logs.readthedocs.io/en/latest/
After=network.target
[Service]
ExecStart=/usr/bin/napalm-logs
Type=simple
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
cat /etc/napalm/logs
log_level: info
port: 514
disable_security: true
extension_config_path: /etc/napalm/additional_config/
device_whitelist:
- ios
- opengear
publisher:
http:
address: 'http://elk.<snip>.<snip>:8080'
method: POST
headers:
Content-Type: application/json
backend: requests
send_raw: true
error_whitelist:
- RXDATA
- UNKNOWN
- RAW
zmq:
address: 0.0.0.0
port: 49017
error_blacklist:
- RXDATA
Hey @gtcat - could you clarify what log rotation are you talking about? Are you referring to the napalm-logs log file /var/log/napalm/logs (http://napalm-logs.com/en/latest/options/index.html#log-file)?
@mirceaulinic - yes I'm referring to the log file /var/log/napalm/logs. Sorry, I forgot to mention that.
Ah, alright, in that case you might want to take a look at logrotate: https://linux.die.net/man/8/logrotate
I used logrotate for other Python applications written by myself and I had to use logging.handlers.WatchedFileHandler in my code because the application needs to be aware of the file being rotated. I already tried logrotate for napalm-logs and the result was that logging did not work anymore after the file has been rotated. A workaround would be to restart the napalm-logs daemon after rotation, but that does not seem to be an optimal solution to me.
I guess the logging code in napalm-logs should be adapted to support logrotate properly.
Interesting, wasn't aware of this.