有没有办法分离安装在轨道内的sinatra app的日志记录

时间:2013-07-19 03:58:49

标签: ruby-on-rails logging sinatra sidekiq

我正在使用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日志中?或者把它放在一个单独的日志文件中?

1 个答案:

答案 0 :(得分:0)

您如何推出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'本身: - )

希望这有帮助。