ruby-on-rails – Puma – 使用配置文件运行服务器时显示完整日志

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Puma – 使用配置文件运行服务器时显示完整日志前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我安装了puma gem,当我通过rails启动rails服务器时,我可以看到完整的输出
  1. $rails s
  2. /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"
  3. => Booting Puma
  4. => Rails 4.1.12 application starting in development on http://0.0.0.0:3000
  5. => Run `rails server -h` for more startup options
  6. => Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
  7. => Ctrl-C to shutdown server
  8. Puma 2.12.3 starting...
  9. * Min threads: 0,max threads: 16
  10. * Environment: development
  11. * Listening on tcp://0.0.0.0:3000
  12.  
  13.  
  14. Started GET "/templates/41" for 127.0.0.1 at 2015-08-06 14:10:32 -0400
  15. Cache read: accont_by_domain/demo.lvh.me ({:expires_in=>86400 seconds})
  16. Dalli::Server#connect 127.0.0.1:11211
  17. Cache fetch_hit: accont_by_domain/demo.lvh.me ({:expires_in=>86400 seconds})
  18. Processing by TemplatesController#show as HTML
  19. Parameters: {"id"=>"41"}
  20. User Load (1.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id",543]]

但是,当我尝试通过提供配置文件来运行puma时,我再也看不到完整的日志了:

  1. $bundle exec puma -C config/puma.rb
  2. [56872] Puma starting in cluster mode...
  3. [56872] * Version 2.12.3 (ruby 2.2.1-p85),codename: Plutonian Photo Shoot
  4. [56872] * Min threads: 1,max threads: 1
  5. [56872] * Environment: development
  6. [56872] * Process workers: 2
  7. [56872] * Preloading application
  8. /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"
  9. [56872] * Listening on tcp://0.0.0.0:3000
  10. [56872] ! WARNING: Detected 1 Thread(s) started in app boot:
  11. [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'
  12. [56872] Use Ctrl-C to stop
  13. [56872] - Worker 0 (pid: 56894) booted,phase: 0
  14. [56872] - Worker 1 (pid: 56895) booted,phase: 0
  15. [56894] 127.0.0.1 - - [06/Aug/2015:14:12:13 -0400] "GET /templates/41 HTTP/1.1" 200 45108 3.3802
  16. [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
  17. [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
  18. ...

有没有办法像rails一样显示日志?我希望在不运行其他命令的情况下拥有与rails s相同的行为.可能吗?

我的美洲狮配置:

  1. workers Integer(ENV['WEB_CONCURRENCY'] || 2)
  2. threads_count = Integer(ENV['MAX_THREADS'] || 1)
  3. threads threads_count,threads_count
  4.  
  5. preload_app!
  6.  
  7. rackup DefaultRackup
  8. port ENV['PORT'] || 3000
  9. environment ENV['RACK_ENV'] || 'development'
  10.  
  11. on_worker_boot do
  12. # Worker specific setup for Rails 4.1+
  13. # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
  14. ActiveRecord::Base.establish_connection
  15. end

解决方法

日志位于log /< rails env> .log中.所以你可以(在一个单独的选项卡/窗口中)运行:
  1. tail -f log/development.log

你会看到你的所有输出.如果你想将rails的输出合并到puma日志中,你可以随时将rails记录到STDOUT:

  1. config.logger = Logger.new(STDOUT)

猜你在找的Ruby相关文章