Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2721b8d
Showing
7 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
examples/campfire.rb |
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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. |
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
on :exit do | |||
put full_log, "#{deploy_to}/deploy.log" | |||
end |
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |