จัดการ log สำหรับ production ใน Rails

ขั้นแรกคือกำหนดว่าใน production mode นี่เราจะใช้ log level ไหน ควรใช้ตั้งแต่ warn ขึ้นไป
config.log_level = :warn
แต่ว่าทั้งนี้ถ้า app นั้นเป็นแบบ internet อาจจะมีพวก bot หรือผู้ใช้อื่นๆ ที่เข้า url ผิทำให้เกิด error 404 หรือ routing error ควรจะกำหนดให้ logger นั้นไม่ได้ทำการ log ส่วนที่ error 404 หรือ routing error โดนเขียนลง ApplicationController
EXCEPTIONS_NOT_LOGGED = ['ActionController::UnknownAction',
                         'ActionController::RoutingError']

protected
  def log_error(exc)
    super unless EXCEPTIONS_NOT_LOGGED.include?(exc.class.name)
  end
แค่นี้ก็ไม่ทำให้ log โตเกินขนาดแล้ว ที่มา: http://maintainablesoftware.com/articles/rails_logging_tips

Posted by Revolution Mon, 21 Jun 2010 04:38:49 GMT

Posted in  | Tags , , , ,  | no comments | no trackbacks

rails kick start

ปกติผมเป็นคนขี้เกียจทำอะไรแบบเริ่มต้นมาก เวลาจะ start project ทีก็จะหาพวกที่เขาทำระบบ authenticate มาให้แล้วส่วนหึง อย่างเช่น Bort แต่หลังๆๆเหมือน Bort จะทำท่ารอ Rails 3.0 หรือกะไรไม่ทราบได้ จึงต้องออกแรงเองหน่อย โดยใช้ rails 2.3.8 กับ authenligic_bundle วิธีใช้ก็แสนง่าย
 $ rails <your-app> -m http://github.com/tsechingho/authlogic_bundle/raw/master/templates/remote.rb
หรือถ้ามี app อยู่แล้วแต่ยังไม่มีระบบ authen ก็ให้ใช้
  $ cd <your-app>
  $ git submodule add git://github.com/tsechingho/authlogic_bundle.git vendor/plugins/authlogic_bundle
  $ rake rails:template LOCATION=vendor/plugins/authlogic_bundle/templates/base.rb SCM=g
แล้วก็สั่ง

  $ rake db:seed
เป็นอันพร้อมใช้งาน

Posted by Revolution Thu, 17 Jun 2010 06:14:08 GMT

Posted in  | Tags , , , ,  | no comments | no trackbacks