Tracking/Logging ActiveRecord Callbacks

前端 未结 4 1850
深忆病人
深忆病人 2020-12-18 00:14

Is there any way to automatically log everytime an ActiveRecord callback happens? It would help to trace through why certain things are happened when a record has several ca

4条回答
  •  醉梦人生
    2020-12-18 00:29

    The easier way is to use the rails native logger methods:

    Debugging Rails Applications

    Using it like this:

    logger.debug "Person attributes hash: #{@person.attributes.inspect}"
    logger.info "Processing the request..."
    logger.fatal "Terminating application, raised unrecoverable error!!!"
    

    Edit:

    To check what was called when an exception ocurred is also interesting to use

    logger.error("trace: #{ex.backtrace().join("\n")}")
    

提交回复
热议问题