Can’t capture chef error to a file

chef

If I run the following:

chef-client --force-formatter --logfile STDOUT 2>&1

And then control-c it mid-run (or encounter any sort of error) I see this nice error message:

[2014-09-12T00:00:30-04:00] FATAL: SIGINT received, stopping

================================================================================
Recipe Compile Error in /var/cache/chef/cookbooks/users/recipes/fen.rb
================================================================================


SystemExit
----------
exit


Cookbook Trace:
---------------
  /var/cache/chef/cookbooks/users/recipes/default.rb:11:in ``'
  /var/cache/chef/cookbooks/users/recipes/default.rb:11:in `from_file'
  /var/cache/chef/cookbooks/users/recipes/fen.rb:15:in `from_file'


Relevant File Content:
----------------------
/var/cache/chef/cookbooks/users/recipes/default.rb:

etc...

[2014-09-12T00:00:30-04:00] ERROR: Running exception handlers
[2014-09-12T00:00:30-04:00] ERROR: Exception handlers complete
[2014-09-12T00:00:30-04:00] FATAL: Stacktrace dumped to /var/cache/chef/chef-stacktrace.out
Chef Client failed. 0 resources updated

But if I do the following:

chef-client --force-formatter --logfile STDOUT 2>&1 | tee /tmp/chef.log

And then control-c, I see all the log messages I was seeing before, with the exception of that nice fatal message telling me what was happening. The file I'm piping too also doesn't show the fatal message.

So apparently chef-client is detecting whether or not it's piping to an actual file descriptor, and suppressing output if it is. Does anyone know of a way to stop it from doing this?

Best Answer

It seems Chef outputs the error to STDERR instead of STDOUT despite specifying STDOUT as logfile. The following command should work:

chef-client --force-formatter --logfile STDOUT 2>&1 | tee /tmp/chef.log