napalm-logs icon indicating copy to clipboard operation
napalm-logs copied to clipboard

How to setup log rotation

Open gbieli opened this issue 6 years ago • 5 comments

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

gbieli avatar Jul 15 '19 09:07 gbieli

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 avatar Sep 02 '19 14:09 mirceaulinic

@mirceaulinic - yes I'm referring to the log file /var/log/napalm/logs. Sorry, I forgot to mention that.

gbieli avatar Sep 09 '19 07:09 gbieli

Ah, alright, in that case you might want to take a look at logrotate: https://linux.die.net/man/8/logrotate

mirceaulinic avatar Sep 11 '19 10:09 mirceaulinic

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.

gbieli avatar Sep 11 '19 11:09 gbieli

Interesting, wasn't aware of this.

mirceaulinic avatar Sep 18 '19 08:09 mirceaulinic