Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@a2ikm
Last active February 15, 2018 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a2ikm/70412b322fa2d27d5888fdc55078266d to your computer and use it in GitHub Desktop.
Save a2ikm/70412b322fa2d27d5888fdc55078266d to your computer and use it in GitHub Desktop.
Tee Capistrano3's logs to stdout and a log file.
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
@a2ikm
Copy link
Author

a2ikm commented Feb 14, 2018

もしかして、単に stdout = $stdout; $stdout = Tee.open(file, stdout: stdout)すれば良かっただけ?
→ $stdoutがFormatterの初期化前に渡される必要があるので、微妙そう。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment