【问题标题】:Is there a way to separate logging for sinatra app mounted inside rails有没有办法为安装在导轨内的 sinatra 应用程序分离日志记录
【发布时间】:2013-07-19 03:58:49
【问题描述】:

我正在使用 sidekiq 管理视图,它是安装在 rails 应用程序内的 Sinatra 应用程序。当我点击管理面板查看我的后台作业时,我得到了很多关于资产的输出,例如:

    16:36:57 web.1    | Started GET "/sidekiq" for 127.0.0.1 at 2013-07-18 16:36:57 -0700
    16:36:57 web.1    | 
    16:36:57 web.1    | 
    16:36:57 web.1    | Started GET "/sidekiq/stylesheets/bootstrap.css" for 127.0.0.1 at 2013-07-18 16:36:57 -0700
    16:36:57 web.1    | 
    16:36:57 web.1    | 
    16:36:57 web.1    | Started GET "/sidekiq/javascripts/application.js" for 127.0.0.1 at 2013-07-18 16:36:57 -0700
    16:36:57 web.1    | 
    16:36:57 web.1    | 
    16:36:57 web.1    | Started GET "/sidekiq/stylesheets/application.css" for 127.0.0.1 at 2013-07-18 16:36:57 -0700
    16:36:57 web.1    | 
    16:36:57 web.1    | 
    16:36:57 web.1    | Started GET "/sidekiq/javascripts/dashboard.js" for 127.0.0.1 at 2013-07-18 16:36:57 -0700
    16:36:57 web.1    | 
    16:36:57 web.1    | 
    16:36:57 web.1    | Started GET "/sidekiq/images/status-sd8051fd480.png" for 127.0.0.1 at 2013-07-18 16:36:57 -0700
    16:36:59 web.1    | 
    16:36:59 web.1    | 
    16:36:59 web.1    | Started GET "/sidekiq/retries" for 127.0.0.1 at 2013-07-18 16:36:59 -0700
    16:36:59 web.1    | 
    16:36:59 web.1    | 
    16:36:59 web.1    | Started GET "/sidekiq/stylesheets/bootstrap.css" for 127.0.0.1 at 2013-07-18 16:36:59 -0700
    16:36

有没有办法让我的 rails 日志不显示这个?或者把它放在一个单独的日志文件中?

【问题讨论】:

  • 你找到什么了吗?我没有使用独角兽,所以下面的答案对我没有帮助。

标签: ruby-on-rails logging sinatra sidekiq


【解决方案1】:

如何启动 Sinatra 应用程序?例如,如果你使用unicorn,你可以在application.rb

require 'sinatra'
require ...

class Application < Sinatra::Base
     configure do
     set :logging, true
     end

end

在用作配置文件的unicorn.rb 文件中,您可以定义此 sinatra 应用程序的日志目录,例如:

[...]

# Set log file paths
stderr_path "#{@dir}log/unicorn.stderr.log"
stdout_path "#{@dir}log/unicorn.stdout.log"

您可以对每个基于机架的 http 服务器执行相同的操作。请注意,保留日志的是 RACK,而不是 'sinatra' 本身 :-)

希望这会有所帮助。

【讨论】:

  • OP 在这里可能没有响应的原因是包含 sidekiq sinatra 应用程序的正常过程是将其安装在 rails config/routes.rb 文件中,因此没有通过 unicorn 明确启动左右,但更确切地说是 rails 负责。默认情况下,安装的应用程序会记录到标准的 rails 日志,该日志会被“污染”。你知道在那里做什么吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-04
  • 1970-01-01
相关资源
最近更新 更多