Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 2721b8d941f702fd70a58774abb6fe50e99467b7 @jnewland committed Feb 27, 2010
Showing with 104 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +14 −0 Capfile
  3. +20 −0 LICENSE
  4. +10 −0 examples/campfire.rb.example
  5. +4 −0 examples/raise.rb
  6. +3 −0 examples/upload.rb
  7. +52 −0 lib/capistrano/log_with_awesome.rb
@@ -0,0 +1 @@
+examples/campfire.rb
14 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
20 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.
@@ -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
@@ -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
@@ -0,0 +1,3 @@
+on :exit do
+ put full_log, "#{deploy_to}/deploy.log"
+end
@@ -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

0 comments on commit 2721b8d

Please sign in to comment.