Rails:logger.debug在Model函数中不起作用

时间:2014-07-22 19:05:59

标签: ruby-on-rails debugging logging

我的logger.debug中有一堆Controller条话。他们目前在我的WEBRick服务器上写下所有HTTP请求和所有内容实时显示的地方。然而, 当我在我的模型中编写logger.debug语句时,它们不会被写入同一位置,另外它们不会出现在log/development中,这是我一直在工作的环境。这特别令人沮丧,因为我在已成功执行logger.debug语句的控制器中调用以下Model函数:

  def process_payment
   uri = URI('https://demo.myvirtualmerchant.com/VirtualMerchant/processxml.do')

   the_xml = SchoolApplication.to_xml(params[:credit_card], 
                                 params[:expiration],
                                 params[:cvv2_cvc2],
                                 params[:amount],
                                 params[:name])
   logger.debug(the_xml)
   the_xml = the_xml.to_s
   my_hash = {'xmldata' => the_xml} 
   logger.debug(the_xml)
   response = Net::HTTP.post_form(uri, my_hash)

   @response_var = response
    if response.response == 0 
      render 'receipt'
    else
      render 'card_Error'
    end
  end

这个控制器方法中的两个logger.debug语句是写成我认为是STDOUT的吗?在任何情况下,我在显示以下类型信息的位置查看

  Rendered web_applications/card_Error.html.erb within layouts/application (1.7ms)
Completed 200 OK in 433ms (Views: 13.1ms | ActiveRecord: 0.0ms)


Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-07-22 11:32:02 -0700

在我调用SchoolApplication.to_xml时,在上面的Controller方法中, 它执行相应的logger.debug()语句(或者它可能会写入它们) 去不同的地方?这不会有意义,但我也是一个明确的n00b to_xml Model方法如下所示:

   def self.to_xml(number,expiration,cvv,amount, name)
     xml = ::Builder::XmlMarkup.new
     logger.debug(number)
     logger.debug(name)
     xml.txn {

       xml.ssl_test_mode false  
       xml.ssl_card_number number
       xml.ssl_amount amount
       xml.ssl_cvv2cvc2_indicator cvv
       xml.ssl_first_name name
       xml.ssl_show_form false
       xml.ssl_exp_date '25/34'
       xml.ssl_track_data 
       xml.ssl_result_format HTML
       xml.ssl_receipt_link_method 
       xml.ssl_receipt_link_url "#{Rails.root}" + '/receipts/receive'
       xml.ssl_receipt_link_text
     }
     xml 
   end

N.B。我知道上面的to_xml被成功调用并返回,因为调用此模型函数的其余控制器方法执行时没有错误。

这是我进入调用process_payment控制器功能的路径后的输出:

Started POST "/application/pay" for 127.0.0.1 at 2014-07-22 12:13:40 -0700
Processing by WebApplicationsController#process_payment as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"pJD6Q7qJPXFNaGEczv5kTSKBC5TcG8lqhOuLNjw9UrY=",  "web_application"=>{"first_name"=>"bob", "last_name"=>"job", "card_number"=>"41111111111111", "expiration_date"=>"232", "cvv2_cvc2"=>"232"}, "commit"=>"Save Web application"}
<txn><ssl_merchant_id/><ssl_user_id/><ssl_ssl_pin/><ssl_test_mode>false</ssl_test_mode>    <ssl_card_number/><ssl_amount/><ssl_cvv2cvc2_indicator/><ssl_first_name/ ><ssl_show_form>false</ssl_show_form><ssl_exp_date>25/34</ssl_exp_date><ssl_track_data/><ssl_result_format>HTML</ssl_result_format><ssl_receipt_link_method/><ssl_receipt_link_url>  <ssl_receipt_link_text/></txn><to_s/>
<txn><ssl_merchant_id/><ssl_user_id/><ssl_ssl_pin/><ssl_test_mode>false</ssl_test_mode>    <ssl_card_number/><ssl_amount/><ssl_cvv2cvc2_indicator/><ssl_first_name/><ssl_show_form>false</ssl_show_form><ssl_exp_date>25/34</ssl_exp_date><ssl_track_data/><ssl_result_format>HTML</ssl_result_format><ssl_receipt_link_method/>
 Rendered web_applications/card_Error.html.erb within layouts/application (3.8ms)
Completed 200 OK in 742ms (Views: 22.6ms | ActiveRecord: 0.0ms)

等同于development.log

中的内容

0 个答案:

没有答案