简体   繁体   English

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

[英]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:我安装了puma gem,当我通过rails s启动 rails 服务器时,我可以看到完整的输出:

$ 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 http://0.0.0.0:3000
=> 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:但是,当我尝试通过提供配置文件来运行 puma 时,我再也看不到完整的日志了:

$ 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?有没有办法像rails s那样显示日志? I want to have the same behaviour as rails s without running additional command.我希望在不运行其他命令rails s情况下具有与rails s相同的行为。 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: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
  ActiveRecord::Base.establish_connection
end

The logs are in log/<rails env>.log .日志在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 :如果您希望将 rails 的输出合并到 puma 日志中,您可以始终将 rails 日志记录到STDOUT

config.logger = Logger.new(STDOUT)

I've found this command in the Puma github readme :我在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.编辑:实际上, 安装 Puma 后所述,它应该由 rails s 命令自动拾取,而无需 Puma 参数。

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 .它会像这样tail -f log/development.log

If you use foreman or a Procfile , you can add the tail -f log to your Procfile .如果您使用foremanProcfile ,您可以将tail -f log添加到您的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 :我实际上在我的.zshrc有一个别名:

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

So I can simply start Rails with:所以我可以简单地启动 Rails:

$> railss

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:...但是我收到了一堆日志错误说: NoMethodError: undefined method 'silence' for #Logger:...

The solution I found was adding to config/environments/development.rb我发现的解决方案是添加到config/environments/development.rb

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

Credits: https://github.com/rails/sprockets-rails/issues/376#issuecomment-287560399学分: https : //github.com/rails/sprockets-rails/issues/376#issuecomment-287560399

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用&#39;rails s puma&#39;通过配置文件运行rails puma服务器 - How to run rails puma server with config file using 'rails s puma' 当我尝试点击 URL 时,Rails 日志在 Puma 的终端中没有显示任何内容:localhost:3000 - Rails logs do not show anything in terminal for Puma when I try to hit the URL: localhost:3000 在centos 7上将puma服务器作为服务运行-未找到红宝石 - run puma server as a service at centos 7 - no ruby found 当我运行`rails server`时,如何让&#39;puma&#39;自动启动(就像Thin一样) - How do I get 'puma' to start, automatically, when I run `rails server` (like Thin does) 美洲狮/缺少日志 - Puma / missing logs Puma Listen循环错误:# <Errno::EBADF: Bad file descriptor> 在puma.rb配置中 - Puma Listen loop error: #<Errno::EBADF: Bad file descriptor> in puma.rb config 将 Puma 作为守护程序启动时未创建 PID 文件 - No PID file created when starting Puma as daemon Cron 不会在 Ubuntu 中自动运行 Rails Puma 服务器 - Cron doesn't run Rails Puma server automatically in Ubuntu 如何在SSL模式下通过Puma服务器运行Rails / Capybara? - How to run Rails/Capybara with Puma server in SSL mode? 是否可以与PUMA Rails服务器在同一过程中运行Sidekiq? - Is it possible to run Sidekiq in the same process with a puma rails server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM