Allow logging to syslog
It would be useful to log via syslog, so that logs can be filtered and sent to remote hosts by the syslog daemon. This can be done by using the "logger" command.
Code is here: https://github.com/xshadow/backupninja/tree/syslog_patch
#5 Updated by drzraf over 1 year ago
- Could you explain why do you:
I'd personally prefer to know from cron output/email if either of echo or logger goes wrong because it'd probably be a big trouble.
- Did you tried if the
logger -p facility.numeric-level
That would permit some code refactoring.
- this line from the patch sounds pretty wrong to me
+ else [ -w "$logfile" ]
wasn't intended to be an
- In the doc patch, logfilepath does not exist (it's logfile)
- @integri? Caring about assuming bash ?
if [[ $syslog == yes ]]
#7 Updated by shadow over 1 year ago
- QA Check changed from Dev Needed to Ready for QA
@drzraf thanks for your input
Somethings were hard to remember, so I had to recheck things before answering.
1. Rewriting shell output
echo 2>/dev/null and logger &>/dev/null
are done, because I think that my patch should not add any output to the current backupninja output.
If you removes those redirections to /dev/null, the run of backupninja will add output on the commandline from which backupninja was excecuted, such as:
[19:21:11] foo@foo:~ $ echo -e "foo" | logger -s -i -t backupninja -p user.2 backupninja: foo
If something goes wrong with your backup, backupninja will still write you an email. And I didn't want to add additional checks if logger is not working correctly. I assume that it's able to log to syslog.
2. numeric logging facilities
I tried that, and it's working, but the loglevels that the authors choosed for backupninja, differ from the loglevels of syslog. So it's not possible to do a:
logger -s -i -t backupninja -p "$syslog_facility"."$loglevel"
without adding a variable for syslog level or changing the loglevels of backupninja. Another variable was not an option because users should not set the loglevel twice. And touching the loglevels of backupninja would be a major code intrusion, which would be a candidate of raising many errors :) So I had to implement this ugly "mapping" here. I choosed a mapping by name, because its easier for the users.
Syslog levels, vs backupninja levels
Syslog: #7 Debug #6 Informational #5 Notice #4 Warning #3 Error #2 Critical #1 Alert #0 Emergency Backupninja # 5 -- Debugging messages (and below) # 4 -- Informational messages (and below) # 3 -- Warnings (and below) # 2 -- Errors (and below) # 1 -- Fatal errors (only)
3. else vs. elif
That's right it's a mistake. Thanks
4. Assuming bash
Backupninja assumes bash at the moment
@intrigerie code is pull able