Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Feature: log to syslog #362

Closed
wants to merge 2 commits into from

4 participants

@antonlindstrom

I missed having the backup output being in the syslog. It's sweet when using centralised logging to have the output in one place.

Logging to syslog was requested in issue #177, however this doesn't add an option to enable or disable the feature.

Cheers!

antonlindstrom added some commits
@antonlindstrom antonlindstrom add log to syslog
This commit adds the default behaviour to log all messages to syslog LOCAL0
facility as well as the regular log file.
e49f077
@antonlindstrom antonlindstrom fix simple syslog tests d8ccf86
@tomash

doesn't seem to intrusive to me. your opinion, @meskyanichi ?

@f440

+1

@ghost

I've pushed changes to the develop branch which adds this feature.
I've also added documentation to the wiki for this:
https://github.com/meskyanichi/backup/wiki/Performing-Backups
https://github.com/meskyanichi/backup/wiki/Logging

If you have a chance, please review these pages, try out the develop branch,
and let me know if you have any problems or if anything is unclear.
Thanks!
/cc @meskyanichi @tomash

@ghost ghost closed this
@antonlindstrom

Cheers!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 26, 2012
  1. @antonlindstrom

    add log to syslog

    antonlindstrom authored
    This commit adds the default behaviour to log all messages to syslog LOCAL0
    facility as well as the regular log file.
  2. @antonlindstrom

    fix simple syslog tests

    antonlindstrom authored
This page is out of date. Refresh to see the latest.
Showing with 41 additions and 0 deletions.
  1. +1 −0  lib/backup.rb
  2. +14 −0 lib/backup/logger.rb
  3. +26 −0 spec/logger_spec.rb
View
1  lib/backup.rb
@@ -4,6 +4,7 @@
require 'rubygems'
require 'fileutils'
require 'tempfile'
+require 'syslog'
require 'yaml'
require 'etc'
View
14 lib/backup/logger.rb
@@ -11,6 +11,7 @@ class << self
def message(string)
to_console loggify(string, :message, :green)
to_file loggify(string, :message)
+ to_syslog loggify(string, :message)
end
##
@@ -19,6 +20,7 @@ def message(string)
def error(string)
to_console loggify(string, :error, :red), true
to_file loggify(string, :error)
+ to_syslog loggify(string, :error), :err
end
##
@@ -28,6 +30,7 @@ def warn(string)
@has_warnings = true
to_console loggify(string, :warning, :yellow), true
to_file loggify(string, :warning)
+ to_syslog loggify(string, :warning), :warn
end
# Outputs the data as if it were a regular 'puts' command,
@@ -35,12 +38,14 @@ def warn(string)
def normal(string)
to_console loggify(string)
to_file loggify(string)
+ to_syslog loggify(string)
end
##
# Silently logs data to the log file
def silent(string)
to_file loggify(string, :silent)
+ to_syslog loggify(string, :silent)
end
##
@@ -120,6 +125,15 @@ def to_file(lines)
end
##
+ # Receives an Array of Strings to be written to syslog.
+ def to_syslog(lines, level = :info)
+ Syslog.open('backup', Syslog::LOG_PID, Syslog::LOG_LOCAL0) do |s|
+ lines.each {|line| s.send(level,line) }
+ end
+ messages.push(*lines)
+ end
+
+ ##
# Invokes the #colorize method with the provided string
# and the color code "32" (for green)
def green(string)
View
26 spec/logger_spec.rb
@@ -33,6 +33,11 @@
returns(:uncolored_regular_message)
subject.expects(:to_file).in_sequence(s).
with(:uncolored_regular_message)
+ subject.expects(:loggify).in_sequence(s).
+ with('regular message', :message).
+ returns(:uncolored_regular_message)
+ subject.expects(:to_syslog).in_sequence(s).
+ with(:uncolored_regular_message)
subject.message('regular message')
end
@@ -50,6 +55,11 @@
returns(:uncolored_error_message)
subject.expects(:to_file).in_sequence(s).
with(:uncolored_error_message)
+ subject.expects(:loggify).in_sequence(s).
+ with('error message', :error).
+ returns(:uncolored_error_message)
+ subject.expects(:to_syslog).in_sequence(s).
+ with(:uncolored_error_message, :err)
subject.error('error message')
end
@@ -67,6 +77,11 @@
returns(:uncolored_warning_message)
subject.expects(:to_file).in_sequence(s).
with(:uncolored_warning_message)
+ subject.expects(:loggify).in_sequence(s).
+ with('warning message', :warning).
+ returns(:uncolored_warning_message)
+ subject.expects(:to_syslog).in_sequence(s).
+ with(:uncolored_warning_message, :warn)
subject.warn('warning message')
end
@@ -74,6 +89,7 @@
it 'sets has_warnings? to true' do
subject.stubs(:to_console)
subject.stubs(:to_file)
+ subject.stubs(:to_syslog)
expect { subject.warn('warning') }.
to change{ subject.has_warnings? }.from(false).to(true)
end
@@ -91,6 +107,11 @@
returns(:unformatted_message)
subject.expects(:to_file).in_sequence(s).
with(:unformatted_message)
+ subject.expects(:loggify).in_sequence(s).
+ with('normal message').
+ returns(:unformatted_message)
+ subject.expects(:to_syslog).in_sequence(s).
+ with(:unformatted_message)
subject.normal('normal message')
end
@@ -104,6 +125,11 @@
returns(:silent_message)
subject.expects(:to_file).in_sequence(s).
with(:silent_message)
+ subject.expects(:loggify).in_sequence(s).
+ with('silent message', :silent).
+ returns(:silent_message)
+ subject.expects(:to_syslog).in_sequence(s).
+ with(:silent_message)
subject.silent('silent message')
end
Something went wrong with that request. Please try again.