title: How to retrieve sane stdout/stderr logging for Elastic Beanstalk deployment
body: <p>When I attempt an elastic beanstalk deployment, one of my <code>container_commands</code> may fail. Unfortunately, the elastic beanstalk log <code>eb-commandprocessor.log</code> only reports a non-zero exit status:</p>
  
  <p><code>Error occurred during build: Command 08_collectstatic failed (Executor::NonZeroExitStatus)</code></p>
  
  <p>The rest of the <code>stdout</code>/<code>stderr</code> apparently fails to log because of Unicode characters. (I've successfully troubleshooted other failed commands because of Unicode quote marks, etc). I have attached the log below.</p>
  
  <hr>
  
  <p>As an example, doing something like <code>ln -s Gruntfile.js Gruntfile.js</code> would raise an error with <code>ln: failed to create symbolic link ‘Gruntfile.js’: File exists</code>. The left- and right- angled quote marks are Unicode and upset Elastic Beanstalk logging -- apparently.</p>
  
  <p><strong>I really need sane output from stdout/stderr to troubleshoot the underlying issue in the container command failure and I don't know how I can patch EB to log this.</strong> How can I achieve this?</p>
  
  <hr>
  
  <p><em>.ebextensions/05_container_commands.config</em></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>option_settings:
    - namespace: aws:elasticbeanstalk:container:python:staticfiles
      option_name: /static/
      value: static/
    - namespace: aws:elasticbeanstalk:container:python
      option_name: WSGIPath
      value: wsgi.py
    - option_name: DJANGO_SETTINGS_MODULE
      value: settings
  
  container_commands:
    08_collectstatic:
      command: "python manage.py collectstatic --noinput"</code></pre>
  </div>
  </div>
  </p>
  
  <hr>
  
  <p><em>/var/log/eb-commandprocessor.log</em></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>-------------------------------------
  /var/log/eb-commandprocessor.log
  -------------------------------------
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 32: ordinal not in range(128)
  Traceback (most recent call last):
    File "/usr/lib64/python2.6/logging/__init__.py", line 799, in emit
      stream.write(fs % msg.encode("UTF-8"))
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 32: ordinal not in range(128)
  Error occurred during build: Command 08_collectstatic failed (ElasticBeanstalk::ActivityFatalError)
   at /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:189:in `rescue in exec'
   ...
  caused by: command failed with error code 1: Traceback (most recent call last):
    File "/usr/lib64/python2.6/logging/__init__.py", line 799, in emit
      stream.write(fs % msg.encode("UTF-8"))
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 32: ordinal not in range(128)
  Traceback (most recent call last):
    File "/usr/lib64/python2.6/logging/__init__.py", line 799, in emit
      stream.write(fs % msg.encode("UTF-8"))
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 32: ordinal not in range(128)
  Traceback (most recent call last):
    File "/usr/lib64/python2.6/logging/__init__.py", line 799, in emit
      stream.write(fs % msg.encode("UTF-8"))
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 32: ordinal not in range(128)
  Traceback (most recent call last):
    File "/usr/lib64/python2.6/logging/__init__.py", line 799, in emit
      stream.write(fs % msg.encode("UTF-8"))
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 32: ordinal not in range(128)
  Traceback (most recent call last):
    File "/usr/lib64/python2.6/logging/__init__.py", line 799, in emit
      stream.write(fs % msg.encode("UTF-8"))
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 32: ordinal not in range(128)
  Error occurred during build: Command 08_collectstatic failed (Executor::NonZeroExitStatus)
   at /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/executor-1.0/lib/executor/exec.rb:81:in `sh'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/executor-1.0/lib/executor/exec.rb:24:in `sh'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/cfn-wrapper.rb:51:in `call_cfn_script'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/cfn-wrapper.rb:28:in `run_config_sets'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/infrahooks/infra-embeddedpostbuild.rb:20:in `execute!'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/executable.rb:56:in `instance_eval'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/executable.rb:56:in `execute!'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/command.rb:213:in `block (3 levels) in exec_stage'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:169:in `call'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:169:in `exec'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:126:in `timeout_exec'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:110:in `block in create'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:109:in `instance_eval'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:109:in `create'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/command.rb:209:in `block (2 levels) in exec_stage'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/command.rb:207:in `each'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/command.rb:207:in `each_with_index'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/command.rb:207:in `block in exec_stage'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:169:in `call'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:169:in `exec'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:126:in `timeout_exec'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:110:in `block in create'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:109:in `instance_eval'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:109:in `create'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/command.rb:204:in `exec_stage'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/command.rb:158:in `execute!'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/command.rb:68:in `run'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/command-processor.rb:64:in `block (2 levels) in execute!'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:169:in `call'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:169:in `exec'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:126:in `timeout_exec'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:110:in `block in create'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:109:in `instance_eval'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/activity.rb:109:in `create'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/command-processor.rb:62:in `block in execute!'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/command-processor.rb:106:in `execute_command'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/lib/elasticbeanstalk/command-processor.rb:60:in `execute!'
   from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.1.0/gems/beanstalk-core-1.1/bin/command-processor:46:in `&lt;top (required)&gt;'
   from /opt/elasticbeanstalk/lib/ruby/bin/command-processor:23:in `load'
   from /opt/elasticbeanstalk/lib/ruby/bin/command-processor:23:in `&lt;main&gt;'</code></pre>
  </div>
  </div>
  </p>