From 2721b8d941f702fd70a58774abb6fe50e99467b7 Mon Sep 17 00:00:00 2001 From: Jesse Newland Date: Sat, 27 Feb 2010 13:56:49 -0500 Subject: [PATCH] initial commit --- .gitignore | 1 + Capfile | 14 ++++++++ LICENSE | 20 ++++++++++++ examples/campfire.rb.example | 10 ++++++ examples/raise.rb | 4 +++ examples/upload.rb | 3 ++ lib/capistrano/log_with_awesome.rb | 52 ++++++++++++++++++++++++++++++ 7 files changed, 104 insertions(+) create mode 100644 .gitignore create mode 100644 Capfile create mode 100644 LICENSE create mode 100644 examples/campfire.rb.example create mode 100644 examples/raise.rb create mode 100644 examples/upload.rb create mode 100644 lib/capistrano/log_with_awesome.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..29340cd --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +examples/campfire.rb diff --git a/Capfile b/Capfile new file mode 100644 index 0000000..18e6335 --- /dev/null +++ b/Capfile @@ -0,0 +1,14 @@ +# Only needed in development +$LOAD_PATH.unshift File.dirname(__FILE__) + '/lib' +require 'capistrano/log_with_awesome' + +# Load the example +Dir['examples/*.rb'].each { |plugin| load(plugin) } + +# Stub deploy tasks to demonstrate the awesome +server 'localhost', :local +set :application, 'test' +set :deploy_to, '/tmp' +task :deploy do + run "uname -a" +end \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3d1aad6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2010 Jesse Newland + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/examples/campfire.rb.example b/examples/campfire.rb.example new file mode 100644 index 0000000..70a8e13 --- /dev/null +++ b/examples/campfire.rb.example @@ -0,0 +1,10 @@ +require 'json' +require 'tinder' +campfire = Tinder::Campfire.new 'yourdomain', :ssl => true +campfire.login 'APIKEY', 'X' +set :room, campfire.find_room_by_name('Log') + +# Log every single cap log line to Campfire. Insane. +on :log_message do + room.speak message +end \ No newline at end of file diff --git a/examples/raise.rb b/examples/raise.rb new file mode 100644 index 0000000..648caf9 --- /dev/null +++ b/examples/raise.rb @@ -0,0 +1,4 @@ +on :log_message do + # Raise an exception and halt the deploy if you're on an ATT 3G card + raise Exception if message =~ /mycingular/ +end \ No newline at end of file diff --git a/examples/upload.rb b/examples/upload.rb new file mode 100644 index 0000000..65ef758 --- /dev/null +++ b/examples/upload.rb @@ -0,0 +1,3 @@ +on :exit do + put full_log, "#{deploy_to}/deploy.log" +end \ No newline at end of file diff --git a/lib/capistrano/log_with_awesome.rb b/lib/capistrano/log_with_awesome.rb new file mode 100644 index 0000000..fa47d28 --- /dev/null +++ b/lib/capistrano/log_with_awesome.rb @@ -0,0 +1,52 @@ +class Capistrano::LogWithAwesome < Capistrano::Logger + + #replaces the built in Capistrano logger with awesome + def self.init(config) + @config = config + level = @config.logger.level + @config.logger = new + @config.logger.level = level + end + + def self.log_with_awesome(message) + @buffer ||= [] + @buffer << message + @config.set :message, message + @config.set :full_log, @buffer.join("\n") + @config.silently_trigger(:log_message) + end + + # Log and do awesome things + # I wish there was a nicer way to do this. Hax on device.puts, maybe? + def log(level, message, line_prefix=nil) + if level <= self.level + indent = "%*s" % [Capistrano::Logger::MAX_LEVEL, "*" * (Capistrano::Logger::MAX_LEVEL - level)] + (RUBY_VERSION >= "1.9" ? message.lines : message).each do |line| + if line_prefix + self.class.log_with_awesome "#{indent} [#{line_prefix}] #{line.strip}" + else + self.class.log_with_awesome "#{indent} #{line.strip}" + end + end + end + super(level, message, line_prefix) + end +end + +module Capistrano + class Configuration + module Callbacks + # Trigger the named event without logging.it + def silently_trigger(event, task=nil) + pending = Array(callbacks[event]).select { |c| c.applies_to?(task) } + if pending.any? + pending.each { |callback| callback.call } + end + end + end + end +end + +Capistrano::Configuration.instance.load do + Capistrano::LogWithAwesome.init(self) +end \ No newline at end of file