title: How can I log the time taken to start a rails app
body: <p>How can I log the start duration taken by a rails application until it is ready to serve requests ?</p>
  <p>A naive approach by adding <code>puts &quot;Rails app booted in #{(boot_start - Time.now)} seconds&quot;</code> in boot.rb` does not work as intended.</p>
  <pre><code># config/boot.rb
  boot_start = Time.now
  
  require &quot;bundler/setup&quot;
  require &quot;bootsnap/setup&quot; if ENV[&quot;RAILS_ENV&quot;] == &quot;development&quot;
  
  puts &quot;Rails app booted in #{(boot_start - Time.now)} seconds&quot;
  </code></pre>
  <p>What I need is</p>
  <ul>
  <li>to print the log entry using Rails.logger defined in the environment</li>
  <li>be accurate as possible (expecially, include the time taken to require all gems, and ideally everything mentioned in <a href="https://guides.rubyonrails.org/initialization.html" rel="nofollow noreferrer">https://guides.rubyonrails.org/initialization.html</a>)</li>
  </ul>
  <p>Note that the naive approach I refered to above prints the duration BEFORE the web server actually starts :</p>
  <pre><code>app_1       | Database 'XXX_staging' already exists
  app_1       | Rails app booted in -1.2772e-05 seconds # Not only it appears before the server is ready
  app_1       | Rails app booted in -1.01e-05 seconds   # But is also duplicated for some reason
  app_1       | =&gt; Booting Puma
  app_1       | =&gt; Rails 6.1.3.2 application starting in staging
  app_1       | =&gt; Run `bin/rails server --help` for more startup options
  app_1       | [12] Puma starting in cluster mode...
  app_1       | [12] * Puma version: 5.3.1 (ruby 3.0.1-p64) (&quot;Sweetnighter&quot;)
  app_1       | [12] *  Min threads: 5
  app_1       | [12] *  Max threads: 5
  app_1       | [12] *  Environment: staging
  app_1       | [12] *   Master PID: 12
  app_1       | [12] *      Workers: 2
  app_1       | [12] *     Restarts: (✔) hot (✖) phased
  app_1       | [12] * Preloading application
  app_1       | [12] * Listening on http://0.0.0.0:3000
  </code></pre>
  <p>I understand the web server is starting asynchronously and the way to measure will be coupled to the actual web server used to run the application (puma in this case) but an example of how this could be achieved using any webserver could be useful.</p>