Puma - 当 运行 服务器带有配置文件时显示完整日志
Puma - show full logs when run server with config file
我安装了 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" = LIMIT 1 [["id", 543]]
然而,当我尝试通过提供配置文件 运行 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
...
有没有办法像 rails s
那样显示日志?我想在没有 运行ning 附加命令的情况下具有与 rails s
相同的行为。可能吗?
我的美洲狮配置:
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
日志在 log/<rails env>.log
中。所以你可以(在单独的选项卡中/window)运行:
tail -f log/development.log
你会看到所有的输出。如果你想将 rails 的输出合并到 puma 日志中,你总是可以让 rails 记录到 STDOUT
:
config.logger = Logger.new(STDOUT)
如果您感兴趣的是日志,那么您可以跟踪实际的日志文件。它会像这样 tail -f log/development.log
.
中找到了这个命令
$rails s Puma
这也会导致所需的行为。
编辑:
事实上,as described here 在安装 Puma 之后,它应该被 rails 的命令自动拾取而没有 Puma 参数。
如果您使用 foreman 或 Procfile
,您可以将 tail -f log
添加到 Procfile
。这是我使用的:
# Procfile.dev
web: bundle exec puma -p $PORT
webpack: bin/webpack-dev-server
log: tail -f log/development.log
然后我这样开始rails:
$> PORT=3000 foreman start -f Procfile.dev
实际上我在 .zshrc
:
中有一个别名
alias railss='PORT=3000 foreman start -f Procfile.dev'
所以我可以简单地从 Rails 开始:
$> railss
就我而言,我试过了
config.logger = Logger.new(STDOUT)
但是我收到了一堆日志记录错误:NoMethodError: undefined method 'silence' for #Logger:...
我找到的解决方案是添加到 config/environments/development.rb
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
致谢:https://github.com/rails/sprockets-rails/issues/376#issuecomment-287560399
我安装了 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" = LIMIT 1 [["id", 543]]
然而,当我尝试通过提供配置文件 运行 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
...
有没有办法像 rails s
那样显示日志?我想在没有 运行ning 附加命令的情况下具有与 rails s
相同的行为。可能吗?
我的美洲狮配置:
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
日志在 log/<rails env>.log
中。所以你可以(在单独的选项卡中/window)运行:
tail -f log/development.log
你会看到所有的输出。如果你想将 rails 的输出合并到 puma 日志中,你总是可以让 rails 记录到 STDOUT
:
config.logger = Logger.new(STDOUT)
如果您感兴趣的是日志,那么您可以跟踪实际的日志文件。它会像这样 tail -f log/development.log
.
$rails s Puma
这也会导致所需的行为。
编辑: 事实上,as described here 在安装 Puma 之后,它应该被 rails 的命令自动拾取而没有 Puma 参数。
如果您使用 foreman 或 Procfile
,您可以将 tail -f log
添加到 Procfile
。这是我使用的:
# Procfile.dev
web: bundle exec puma -p $PORT
webpack: bin/webpack-dev-server
log: tail -f log/development.log
然后我这样开始rails:
$> PORT=3000 foreman start -f Procfile.dev
实际上我在 .zshrc
:
alias railss='PORT=3000 foreman start -f Procfile.dev'
所以我可以简单地从 Rails 开始:
$> railss
就我而言,我试过了
config.logger = Logger.new(STDOUT)
但是我收到了一堆日志记录错误:NoMethodError: undefined method 'silence' for #Logger:...
我找到的解决方案是添加到 config/environments/development.rb
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
致谢:https://github.com/rails/sprockets-rails/issues/376#issuecomment-287560399