Puma - show full logs when run server with config file

I installed puma gem and when I start rails server by rails s I can see full output:

$ rails s /Users/serj/.rvm/gems/ruby-2.2.1@email_platform/gems/htmlentities-4.3.2/lib/htmlentities/mappings/expanded.rb:465: warning: duplicated key at line 466 ignored: "inodot" => Booting Puma => Rails 4.1.12 application starting in development on => Run `rails server -h` for more startup options => Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option) => Ctrl-C to shutdown server Puma 2.12.3 starting... * Min threads: 0, max threads: 16 * Environment: development * Listening on tcp://0.0.0.0:3000 Started GET "/templates/41" for 127.0.0.1 at 2015-08-06 14:10:32 -0400 Cache read: accont_by_domain/demo.lvh.me ({:expires_in=>86400 seconds}) Dalli::Server#connect 127.0.0.1:11211 Cache fetch_hit: accont_by_domain/demo.lvh.me ({:expires_in=>86400 seconds}) Processing by TemplatesController#show as HTML Parameters: {"id"=>"41"} User Load (1.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 543]] 

However when I try to run puma by providing config file I can't see full logs anymore:

$ bundle exec puma -C config/puma.rb [56872] Puma starting in cluster mode... [56872] * Version 2.12.3 (ruby 2.2.1-p85), codename: Plutonian Photo Shoot [56872] * Min threads: 1, max threads: 1 [56872] * Environment: development [56872] * Process workers: 2 [56872] * Preloading application /Users/serj/.rvm/gems/ruby-2.2.1@email_platform/gems/htmlentities-4.3.2/lib/htmlentities/mappings/expanded.rb:465: warning: duplicated key at line 466 ignored: "inodot" [56872] * Listening on tcp://0.0.0.0:3000 [56872] ! WARNING: Detected 1 Thread(s) started in app boot: [56872] ! #<Rack::MiniProfiler::FileStore::CacheCleanupThread:0x007fb58ccaa730@/Users/serj/.rvm/gems/ruby-2.2.1@email_platform/gems/rack-mini-profiler-0.9.7/lib/mini_profiler/storage/file_store.rb:47 sleep> - /Users/serj/.rvm/gems/ruby-2.2.1@email_platform/gems/rack-mini-profiler-0.9.7/lib/mini_profiler/storage/file_store.rb:65:in `sleep' [56872] Use Ctrl-C to stop [56872] - Worker 0 (pid: 56894) booted, phase: 0 [56872] - Worker 1 (pid: 56895) booted, phase: 0 [56894] 127.0.0.1 - - [06/Aug/2015:14:12:13 -0400] "GET /templates/41 HTTP/1.1" 200 45108 3.3802 [56894] 127.0.0.1 - - [06/Aug/2015:14:12:13 -0400] "GET /bootstrap-image-gallery.css?body=1 HTTP/1.1" 304 - 0.0379 [56894] 127.0.0.1 - - [06/Aug/2015:14:12:13 -0400] "GET /jquery.ui.autocomplete.css?body=1 HTTP/1.1" 304 - 0.0427 ... 

Is there any way to show logs as rails s does? I want to have the same behaviour as rails s without running additional command. Is it possible?

My puma config:

workers Integer(ENV['WEB_CONCURRENCY'] || 2) threads_count = Integer(ENV['MAX_THREADS'] || 1) threads threads_count, threads_count preload_app! rackup DefaultRackup port ENV['PORT'] || 3000 environment ENV['RACK_ENV'] || 'development' on_worker_boot do # Worker specific setup for Rails 4.1+ # See: ActiveRecord::Base.establish_connection end 

6 Answers

The logs are in log/<rails env>.log. So you could (in a separate tab / window) run:

tail -f log/development.log 

And you'll see all your output. If you want the output from rails merged into the puma logs, you could always have rails log to STDOUT:

config.logger = Logger.new(STDOUT) 
0

I've found this command in the Puma github readme:

$rails s Puma 

Which also results in the desired behavior.

Edit: In fact, as described here after installing Puma, it should automatically be picked up by rails s command without the Puma argument.

If it's the logs you're interested in, then you can tail the actual log file. It'd go something like this tail -f log/development.log.

0

If you use foreman or a Procfile, you can add the tail -f log to your Procfile. This is what I use:

# Procfile.dev web: bundle exec puma -p $PORT webpack: bin/webpack-dev-server log: tail -f log/development.log 

I then start rails like this:

$> PORT=3000 foreman start -f Procfile.dev 

I actually have an alias for this in my .zshrc:

alias railss='PORT=3000 foreman start -f Procfile.dev' 

So I can simply start Rails with:

$> railss 
1

In my case, I tried

config.logger = Logger.new(STDOUT) 

But I got a bunch of logging errors saying: NoMethodError: undefined method 'silence' for #Logger:...

The solution I found was adding to config/environments/development.rb

logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) 

Credits:

It might occur due the following line in your Puma config file:

workers Integer(ENV['WEB_CONCURRENCY'] || 2) 

Try to remove this line or set workers to 0.

This way Puma is going to run on single mode and start to print all logs.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like