2010-10-24 58 views
0

我試圖將生產環境日誌保存到其他服務器上的數據庫..我的意思是,當出現一些錯誤時,我想打開ssh並檢查production.log的結尾。我想要的是去另一個數據庫(可能在其他服務器上)螞蟻檢查出來。如何將Rails日誌保存到應用程序之外的數據庫?

我想記錄的信息是相同的,因爲我在* .LOG看到,包含錯誤的代碼跟蹤,該錯誤發現行,數據庫查詢,以及HTTP響應..

像對此,

Processing Admin::WelcomeController#login (for XXX.XXX.XXX.XXX at 2010-08-27 00:02:41) [POST] 
    Parameters: {"username_or_email"=>"admin", "action"=>"login", "authenticity_token"=>"oPMZYGi+k/Wvxxxxxv2oNU0w34PV2KNSENuwn8=", "controller"=>"admin/welcome", "password"=>"[FILTERED]"} 
Redirected to http://beta.site.com/admin/pages 
Completed in 19ms (DB: 13) | 302 Found [http://beta.site.com/admin/login] 

和類似的東西

Processing Admin::PagesController#edit (for 213.6.226.204 at 2010-09-02 14:18:43) [GET] 
    Parameters: {"action"=>"edit", "id"=>"14", "controller"=>"admin/pages"} 
Rendering template within layouts/application 
Rendering admin/pages/edit 

ActionView::TemplateError (undefined method `include?' for nil:NilClass) on line #26 of /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/radiant-0.9.1/app/views/admin/pages/_fields.html.haml: 
23:   %a.popup{:href=> '#add_part_popup', :title=>t('add_part')} 
24:    = image('add_tab', :alt=>t('add_part'), :title=>"") 
25:  #pages.pages 
26:   = render :partial => 'admin/page_parts/page_part', :collection => @page.parts 
27:  = render_region :parts_bottom, :locals => {:f => fields} 
28: - form.edit_layout_and_type do 
29:  .set 

    /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/will_paginate-2.3.14/lib/will_paginate/finder.rb:168:in `method_missing' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers/action_view_mods.rb:11:in `render' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers.rb:90:in `non_haml' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers/action_view_mods.rb:11:in `render' 
    radiant (0.9.1) app/views/admin/pages/_fields.html.haml:26 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers.rb:343:in `call' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers.rb:343:in `capture_haml' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers.rb:545:in `with_haml_buffer' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers.rb:339:in `capture_haml' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers/action_view_mods.rb:88:in `capture' 
    radiant (0.9.1) lib/radiant/admin_ui/region_partials.rb:13:in `method_missing' 
    radiant (0.9.1) app/views/admin/pages/_fields.html.haml:19 
    radiant (0.9.1) app/helpers/admin/regions_helper.rb:6:in `call' 
    radiant (0.9.1) app/helpers/admin/regions_helper.rb:6:in `render_region' 
    radiant (0.9.1) app/views/admin/pages/_fields.html.haml:6:in `_run_haml_47opt47ruby45enterprise47lib47ruby47gems47146847gems47radiant45046946147app47views47admin47pages47_fields46html46haml_locals_fields_object' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers/action_view_mods.rb:11:in `render' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers.rb:90:in `non_haml' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers/action_view_mods.rb:11:in `render' 
    radiant (0.9.1) app/views/admin/pages/edit.html.haml:8 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers/action_view_mods.rb:204:in `call' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers/action_view_mods.rb:204 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers.rb:567:in `call' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers.rb:567:in `haml_bind_proc' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers/action_view_mods.rb:210:in `form_for' 
    radiant (0.9.1) app/views/admin/pages/edit.html.haml:7 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers.rb:343:in `call' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers.rb:343:in `capture_haml' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers.rb:545:in `with_haml_buffer' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers.rb:339:in `capture_haml' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers/action_view_mods.rb:88:in `capture' 
    radiant (0.9.1) lib/radiant/admin_ui/region_partials.rb:13:in `method_missing' 
    radiant (0.9.1) app/views/admin/pages/edit.html.haml:6 
    radiant (0.9.1) app/helpers/admin/regions_helper.rb:6:in `call' 
    radiant (0.9.1) app/helpers/admin/regions_helper.rb:6:in `render_region' 
    radiant (0.9.1) app/views/admin/pages/edit.html.haml:3:in `_run_haml_47opt47ruby45enterprise47lib47ruby47gems47146847gems47radiant45046946147app47views47admin47pages47edit46html46haml' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers/action_view_mods.rb:13:in `render' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/haml/helpers/action_view_mods.rb:13:in `render' 
    radiant (0.9.1) vendor/plugins/haml/rails/./lib/sass/plugin/rails.rb:20:in `process' 
    passenger (2.2.11) lib/phusion_passenger/rack/request_handler.rb:92:in `process_request' 
    passenger (2.2.11) lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop' 
    passenger (2.2.11) lib/phusion_passenger/railz/application_spawner.rb:418:in `start_request_handler' 
    passenger (2.2.11) lib/phusion_passenger/railz/application_spawner.rb:358:in `handle_spawn_application' 
    passenger (2.2.11) lib/phusion_passenger/utils.rb:184:in `safe_fork' 
    passenger (2.2.11) lib/phusion_passenger/railz/application_spawner.rb:354:in `handle_spawn_application' 
    passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:352:in `__send__' 
    passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:352:in `main_loop' 
    passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously' 
    passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:163:in `start' 
    passenger (2.2.11) lib/phusion_passenger/railz/application_spawner.rb:213:in `start' 
    passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:262:in `spawn_rails_application' 
    passenger (2.2.11) lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add' 
    passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:256:in `spawn_rails_application' 
    passenger (2.2.11) lib/phusion_passenger/abstract_server_collection.rb:80:in `synchronize' 
    passenger (2.2.11) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize' 
    passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:255:in `spawn_rails_application' 
    passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:154:in `spawn_application' 
    passenger (2.2.11) lib/phusion_passenger/spawn_manager.rb:287:in `handle_spawn_application' 
    passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:352:in `__send__' 
    passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:352:in `main_loop' 
    passenger (2.2.11) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously' 

Rendering /home/deploy/xxxx/public/500.html (500 Internal Server Error) 

任何訣竅是歡迎:)

Amr

回答

-1

Rails logger顯然不能做你想要的東西。

一種選擇是寫入syslog(http://www.blueboxgrp.com/news/2009/06/unified_rails_logging_with_syslog-ng)並使用可將日誌條目推送到數據庫的syslog-ng(mysql,postgres ,sqlite,http://chaos.untouchable.net/index.php/HOWTO_setup_syslog-ng_to_log_to_mysql)。你必須做一些配置才能使這一切工作,再加上調整軌道來配置生產模式下的更多信息。問題在於,每當您的應用程序獲得請求時,它會多次寫入日誌,因此您會爲數據庫中的每個請求獲取多條記錄。

還有另一種服務,在今年Rails Rumble期間創建(抱歉插件!)http://logbook.me,您可以使用它來記錄任何內容。使用當前版本的gem,您需要手動執行一些工作(捕獲異常,捕獲您感興趣的細節+回溯並將它們傳遞給服務),但我們計劃擴展它以便它自動處理更多東西。

相關問題