LoginSignup
1
1

More than 5 years have passed since last update.

【Capistrano3】実行タスク名をログに出力したい

Last updated at Posted at 2014-10-25

方法

実行コマンドに--traceつけるだけだった・・・
capistrano2系だとlog_levelでTRACEとかいうのが指定できるらしいが3系では出来ない様子。

出力内容

** Invoke deploy:xxxxx (first_time)
** Execute deploy:xxxxx

のような感じを区切りに、タスクの実行状況が出力される。

cap development deploy:test_task_1 --trace # test_task_1のあとにtest_task_2が走るようなタスク

最初にバリデーション?がガーッと走っている。

** Invoke development (first_time)
** Execute development
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
** Invoke deploy:set_rails_env (first_time)
** Execute deploy:set_rails_env
** Invoke deploy:set_rails_env
** Invoke rbenv:validate (first_time)
** Execute rbenv:validate
DEBUG[53f4b596] Running /usr/bin/env [ ! -d ~/.rbenv/versions/2.0.0-p451 ] on 192.xxx.xx.xx
DEBUG[53f4b596] Command: [ ! -d ~/.rbenv/versions/2.0.0-p451 ]
DEBUG[53f4b596] Finished in 0.112 seconds with exit status 1 (failed).
** Invoke rbenv:map_bins (first_time)
** Execute rbenv:map_bins
** Invoke deploy:test_task_1 (first_time)
** Execute deploy:test_task_1
INFO[1361267d] Running /usr/bin/env echo abcdefg on 192.xxx.xx.xx
DEBUG[1361267d] Command: echo abcdefg
DEBUG[1361267d]   abcdefg
INFO[1361267d] Finished in 0.028 seconds with exit status 0 (successful).
** Invoke deploy:test_task_2 (first_time)
** Execute deploy:test_task_2
INFO[ff511f2f] Running /usr/bin/env echo hijklmn on 192.xxx.xx.xx
DEBUG[ff511f2f] Command: echo hijklmn
DEBUG[ff511f2f]   hijklmn
INFO[ff511f2f] Finished in 0.032 seconds with exit status 0 (successful).

ファイル出力したい

この画面の出力のままファイルに出力してくれればいいのに、
普通に > だと、InvokeとExecuteのログが別プロセス?で出力してるらしく、
結局まとまって出力されてしまうので、意味がない!

苦肉の策

script -q -t 0 log.txt cap development deploy:test_task_1 --trace

順番どおりにファイル出力されるようになった!

ただし、capistrano3が色付けしている形跡も一緒に出されてしまうので、非常に見難い。
解決策はまだ見つからない。つらい。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1