Feature #3462

Allow logging to syslog

Added by erikg almost 7 years ago. Updated about 2 years ago.

Target version:
Start date:
Due date:
% Done:


QA Check:
Ready for QA


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:

syslog_patch (2.61 KB) shadow, 10/27/2014 09:54 AM

syslog_patch_with_facilities (3.47 KB) shadow, 10/28/2014 06:49 PM


#1 Updated by intrigeri almost 7 years ago

  • Category set to backupninja
  • Status changed from New to Confirmed
  • Priority changed from Normal to Low

I agree this would be great. Patches welcome!

#2 Updated by shadow over 3 years ago

I agree this would be great. Patch as attachement.

#3 Updated by shadow over 3 years ago

I created another patch, where you can enable logging to syslog. Log on different severity levels depending on the choosen loglevel and enable logging to different facility levels.

#4 Updated by intrigeri over 3 years ago

  • Subject changed from Use syslog for logging to Allow logging to syslog
  • % Done changed from 0 to 30
  • QA Check set to Ready for QA

#5 Updated by drzraf over 2 years ago

  • Could you explain why do you:
    echo 2>/dev/null

    and why
    logger &>/dev/null

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

    syntax works?
    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 ]]

#6 Updated by intrigeri over 2 years ago

  • Assignee set to shadow
  • QA Check changed from Ready for QA to Dev Needed

#7 Updated by shadow about 2 years 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
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[9845]: 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


#7       Debug
#6       Informational
#5       Notice
#4       Warning
#3       Error
#2       Critical
#1       Alert
#0       Emergency

# 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

5. Codebase

@intrigerie code is pull able

#8 Updated by shadow about 2 years ago

  • Description updated (diff)
  • Assignee changed from shadow to drzraf
  • % Done changed from 30 to 40

#9 Updated by drzraf about 2 years ago

  • Assignee changed from drzraf to intrigeri

would be fair to assign intrigeri :)

Also available in: Atom PDF