Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit e49f077e4ac64eb612b07382076f5bb51d1ec6d0 1 parent 5639587
@antonlindstrom authored
Showing with 15 additions and 0 deletions.
  1. +1 −0  lib/backup.rb
  2. +14 −0 lib/backup/logger.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), :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), :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)

0 comments on commit e49f077

Please sign in to comment.
Something went wrong with that request. Please try again.