title: Create an audit log from irb or rails console?
body: <p>As part of the security procedures for our Rails application, we want to have an audit log of the commands that were run from rails console in our production environment. </p>
  
  <p>This audit log should be persisted somewhere, such as a database, a file in an S3 bucket, or similar. If it could be written to the standard rails log, that might be OK too, as we already have a way to persist that.</p>
  
  <p>We're currently hosted on Heroku. Heroku will log the event of firing up a console, but (a) Heroku provides no functionality for logging commands run from an active console, and (b) we'd like a more general-purpose solution.</p>
  
  <p>Are there any pre-existing solutions for this out there?</p>
  
  <hr>
  
  <p>If there is none, I'm trying to figure out how to monkey-patch IRB or Rails Console.</p>
  
  <p>I've discovered that the data I need is already in </p>
  
  <pre><code>Readline::HISTORY
  </code></pre>
  
  <p>but I'm struggling to figure out where/how to hook into it.</p>
  
  <p>Ideally, I'd like to capture each entry as (before?) it is sent to the interpreter, and quickly persist it somewhere (we already have Resque, so that may be a good solution). FWIW, sending the contents of Readline::HISTORY on Kernel.exit seems like it may be unreliable. For example, if a SIGKILL stops the process, then the history contents wouldn't be saved.</p>