Capistranoã§ãã°ãæ¨æºåºåã¨ãã¡ã¤ã«åºåã®ä¸¡æ¹ã«åºåããæ¹æ³
ãã£ã¨ã·ã³ãã«ã«ã§ããããæ¹ãããã°æãã¦ãã ããã¾ãï¼
chefãåããã¦ããCapistranoã®ãã°ããããªã«ããå¿
è¦ããã
æ¨æºåºåã¨ãã¡ã¤ã«åºåã®ä¸¡æ¹ã«åºåãããã¨ã¯ã§ããªãããªã¨æªæ¦è¦éããè¨é²ã«ãªãã¾ãã
- åè
capturing output to log file
require 'capistrano'
require 'capistrano/logger'output = '/var/log/capistrano.log'
custom_logger = Capistrano::Logger.new(:output => output)
custom_logger.level = Capistrano::Logger::TRACE
self.logger = custom_logger
ã¾ãããã¡ãã®è¨å®ã§æ¨æºåºåã¯è¡ããããã¡ã¤ã«åºåããããã¨ã確èªã
ã§ã¯åããã¦æ¨æºåºåã«åºãã«ã¯outputãããã²ã¨ã¤æå®ããããããªã«ãã¦ãããã ããã¨ã
custom_logger = Capistrano::Logger.new(:output => output)â
custom_logger = Capistrano::Logger.new(:output => output, :output => STDOUT)
1ã¤ç®ã®outputå¼æ°ã2ã¤ç®ã®outputå¼æ°ã«ä¸æ¸ãããã¦çµããã
ããç°¡åã«ã¯ãããªãã§ãããã
ã¨ãããã¨ã§Capistranoã®ä¸èº«ã確èªããã¨logé¢ä¿ã¯
/lib/capistrano/logger.rbããã«ããããã ãªã¨ã
def initialize(options={})
output = options[:output] || $stderr
if output.respond_to?(:puts)
@device = output
else
@device = File.open(output.to_str, "a")
@needs_close = true
end@options = options
@level = 0
enddef close
device.close if @needs_close
enddef log(level, message, line_prefix=nil)
if level <= self.level
indent = "%*s" % [MAX_LEVEL, "*" * (MAX_LEVEL - level)]
message.each do |line|
if line_prefix
device.puts "#{indent} [#{line_prefix}] #{line.strip}\n"
else
device.puts "#{indent} #{line.strip}\n"
end
end
end
end
putsã£ã¦ã¡ã½ãããããã°deviceã£ã¦ã®ã«æ ¼ç´ãããã¨ãããã£ãã®ã§
ãããå½è£
ãã¦ããã°ãããã ãã¨ãããã¨ããããã¾ãã
config/mydevice.rb
class MyDeviceattr_accessor :buffer
def puts(msg)
STDOUT.puts(msg)
@buffer = @buffer + msg
end
def tty?
return false
end
def initialize
@buffer = ""
end
def clone
end
end
ãããªé¢¨ã«STDOUT(æ¨æºåºå)ã¨@buffer(ãã¡ã¤ã«åºåã®ããã®å¤æ°)ã«åºåããããã«ãã¾ãã
deploy.rb
require 'capistrano'
require 'capistrano/logger'
load 'config/mydevice'self.logger.device = MyDevice.new
ããã¦deploy.rbã«ä¸è¨è¨è¿°ãæ¸ããã¨ã§ãè¨å®ãä¸æ¸ãããã¾ãã
task :message do
open("/tmp/capistrano.log", "w") {|f| f.write self.logger.device.buffer}
end
ãããªæãã§messageãåºåããtaskãè¨è¼ãããã¨ã§
/tmp/capistrano.logã¸ä¸æ¸ãã§åºåãã¦ããã¾ãã
Perlã®ãã¼ã«ã§ããããªã«ã³ã¼ããèªãã ãã¨ã¯ãªãã£ãã®ã§
ã©ããã£ã¦èªãã§ãã£ãããããã®ãã£ããã«ãªã£ãã®ã¨ãã¯ã©ã¹ã¨ããããããã®ã
ã¼ãããã¨ããã£ã¦ãããããªæ°ããã¾ãã