Last active
February 15, 2018 03:04
-
-
Save a2ikm/70412b322fa2d27d5888fdc55078266d to your computer and use it in GitHub Desktop.
Tee Capistrano3's logs to stdout and a log file.
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
before :deploy, :setup_tee do | |
require "tee" # tee gem | |
# root is where Capfile is placed. | |
root = File.dirname(File.expand_path(Rake.application.rakefile)) | |
path = File.join(root, "log/deploy_#{release_timestamp}_#{local_user}.log") | |
FileUtils.mkdir_p(File.dirname(path)) | |
file = File.open(path, "w").tap { |f| f.sync = true } | |
formatter = SSHKit.config.output | |
org = formatter.instance_variable_get(:@original_output) | |
tee = Tee.open(file, stdout: org) | |
formatter.instance_variable_set(:@original_output, tee) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
もしかして、単に
stdout = $stdout; $stdout = Tee.open(file, stdout: stdout)
すれば良かっただけ?→ $stdoutがFormatterの初期化前に渡される必要があるので、微妙そう。