When running Puma as a daemon (i.e. using the -d flag), Puma does not seem to log to the location specified by stdout_redirect.
Has anyone seen this behavior before and if so, found a workaround to generate the proper log files for Puma (specifically with the stdout_redirect in place, and specifically for a Ruby on Rails application)?
The reason
stdout_redirectis not working is becauseconfig/puma.rbis never run when you runrails server -d. You can demonstrate this for yourself by changing the port number or even introducing a syntax error in the file.Puma runs as a Rack server and is thus launched by the Rack middleware. The Rack code just uses the core Ruby
Processclass to detach the process:Unfortunately,
Process.daemondoes two things by default:/dev/null.So, when the Puma server initializes, all process output is binned and since
/config/puma.rbdoesn't exist, puma falls back to its hardcoded default settings.You can actually demonstrate the behavior you want if you temporarily hack the
rackcode to override the chdir behaviour:If the first parameter to
.daemonistrueit does not change the current working directory, and thus theconfig/puma.rbgets run.Short of some kind of ugly monkey-patch to Rack, a (possibly also ugly) workaround would be to skip the
-doption and roll your own inconfig/puma.rb. For example:Then: