Created
January 19, 2010 01:40
-
-
Save ydnar/280573 to your computer and use it in GitHub Desktop.
Quick patch to enable Capistrano to use Syslog via the Logging gem.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Workaround in case Logging symbol is partially loaded/defined | |
Object.send(:remove_const, :Logging) if defined?(Logging) | |
# http://gemcutter.org/gems/logging | |
require 'logging' | |
# Use Syslog | |
class Capistrano::Logger | |
LOGGER_NAME = "capistrano" | |
def log(level, message, line_prefix=nil) | |
return unless level <= self.level | |
logger.level = convert(self.level) | |
indent = "%*s" % [MAX_LEVEL, "*" * (MAX_LEVEL - level)] | |
(RUBY_VERSION >= "1.9" ? message.lines : message).each do |line| | |
msg = line_prefix ? "#{indent} [#{line_prefix}] #{line.strip}" : "#{indent} #{line.strip}" | |
logger.add convert(level), msg | |
end | |
end | |
private | |
# Capistrano log levels are (sort of) the opposite of convention. | |
def convert(level) | |
[MAX_LEVEL - level, 0].max | |
end | |
def logger | |
unless defined?(@logger) | |
@logger = Logging::Logger[LOGGER_NAME] | |
@logger.add_appenders(Logging::Appenders::Stderr.new) | |
@logger.add_appenders(Logging::Appenders::Syslog.new(LOGGER_NAME, :facility => Syslog::Constants::LOG_USER)) | |
end | |
@logger | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment