จัดการ 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

gedit และ vim เพื่อการทดแทน textmate

ไม่เคยใช้ mac หรือนะ เลยไม่เคยมี textmate แต่คิดว่า gedit นี่ก็โอเคแล้ว Gmate: http://github.com/lexrupy/gmate/ วิธีลงก็

$ git clone git://github.com/lexrupy/gmate.git   
$ cd gmate 
$ sh install.sh
แจ่มสุดๆ ใช้ gedit open file ส่วนบางครั้งมันอยากแก้เร็วๆ เลยใช้ vim vimfile: http://github.com/akitaonrails/vimfiles วิธีลงก็
$ git clone git://github.com/akitaonrails/vimfiles.git .vim
$cd .vim
$ git submodule init
$ git submodule update
$ cp vimrc ~/.vimrc
ของอีตา akita ก็ดีอย่างคือเวลา module อื่นๆ มัน update เราแค่ทำคำสั่ง
git submodule update
มันก็ update

Posted by Revolution Mon, 23 Nov 2009 16:17:16 GMT

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

Typo consumer too much memory

I monitor this application typo 5.0.2 consume too much memory about 50 – 80 MB which full feature. So i will try to make lite version for typo because I still like it. By the way, If my try is not successful, I will make my own blog system

มันกิน mem มากเหลือเกินไม่ไหว ถ้ามีโอกาศ จะลองทำแบบ lite ดู แต่ถ้าไม่ได้ลองเขียนใช้เองแล้ว ไม่ไหวเปลือง

Posted by Revolution Tue, 29 Apr 2008 07:08:41 GMT

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

Typo 5.0.2

เปลี่ยนไปเยอะมาก ทั้ง front end และ back end มีการจัดวางเมนูได้ดีขึ้น ใช้ง่ายขึ้น สามารถ edit theme ได้บางส่วน ที่สำคัญยังเพิ่มระบบ multi user ด้วย ป.ล. ถ้าจะให้ดีทำ ระบบ plugin ให้ง่ายกว่านี้ก็ดีนะ อยากได้ revision เหมือน drupal จะได้เป็น Wiki ได้ด้วย

Posted by Revolution Wed, 16 Jan 2008 16:21:24 GMT

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

Ultraviolet Hack แบบใช้ไปก่อน

วิธีการก็เอา syntax ที่มีอยู่ใน typo มา hack ซะ ซึ่งมันเป็น macro อยู่แล้ว จาก plugin ชื่อ typo_textfilter_code ก็ copy ทั้ง folder มาเป็นชื่อ typo_textfilter_uvcode จากนั้นก็แก้ทุกอย่างที่เดิมเป็น code ให้เป็น uvcode แล้วก็แก้ไฟล์ typo_textfilter_uvcode/lib/typo_textfilter_uvcode.rb ดังนี้

<typo:uvcode lang="ruby"> def self.macrofilter(blog,content,attrib,params,text="")

    lang       = attrib['lang'] || "plain_text"
    title      = attrib['title']
    cssclass   = attrib['class'] || 'iplastic'
    linenumber = attrib['linenumber'] || false

    text = text.to_s.gsub(/\r/,'').gsub(/\A\n/,'').chomp
    convertor = Uv
    text = convertor.parse(text, "xhtml", lang, linenumber, cssclass)

    "<div class=\"typocode\">#{text}</div>"   

end </typo:uvcode>

จากนั้นก็เอา css จะใช้ไปใส่ที่ public/stylesheets/user-style.css ในนี้เพิ่ม <typo:uvcode lang="css"> overflow: auto; </typo:uvcode> เข้าไปใน class pre

Posted by Revolution Wed, 21 Nov 2007 12:43:24 GMT

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

Typo is hebinated

Piers Cawley หนึ่งใน main developer ของ typo ออกมาพูดใน blog ตัวเอง
ถึงการหยุดนิ่งของ typo และยังมีการชมเชย Mephisto ที่มีการทำงานที่ดีกว่า typo ทำให้ developer ทำงานได้ง่ายด้วยการเขียน code ที่สะอาด

แต่ไม่นานมานี้ดูท่าจะมีการเปลี่ยนแปลงครั้งใหญ่กัน typo (และคงอีกหลายๆตัว) กับการมาของ rails 2.0 จะรอดีหรือจะ folk ดี หรือจะเขียนเองดีน้า….

อยากได้ plugin เหมือน jazzy ใน Mephisto ไปถาม punneng ดีกว่า

Posted by Revolution Wed, 21 Nov 2007 05:19:22 GMT

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

Redgem Project for Rails Hosting

I’m a ruby programming hobbyist and doing rails hosting in Thailand especially ruby (and rails). Because in Thailand, there is nobody doing rails hosting. In fact, I fall in love with ruby as much as i written. One factor that make ruby grow up, there is a product that can release ruby and rails powers. So I decide to do Control panel for Rails hosting in ruby programming.

This project is base on vhcs2 concept with additional features. I draw some concept of control panel with freemind software

I call this project name “REDGEM” and now I opening project to rubyforge.org and get approve alrady. It can be accessed to redgem project

For rough concept, I separate work into 2 path

  1. Web Control Panel – It is written by Ruby on Rails. This part is interacted with user.
  2. Engine – It is also written by Ruby. The engine has responsibility to edit file configuration and deployment

For Future design, UI it may not be a web, it can be other or other language

As you see this is not easy one to do, I need help. Anyone can help me please let me know.

Thank You

File: redgem concept

ภาษาไทยข้างใน

Posted by Revolution Mon, 19 Nov 2007 11:31:42 GMT

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

file_column

พอดีมีทำ upload ทั้งรูปและไฟล์ pdf ด้วย file_column แต่มีการกำหนดไว้ว่าให้ resize รูปที่ขึ้นไป พอ upload pdf ก็เกิดปัญหานะสิเพราะมัน resize ทำ thumbnail ไม่ได้ (ที่จริงก็ได้แต่ยังไงไม่รู้) เพราะมันจะทำให้ WebBrick crash ไป และก็ขี้เกียจไปสร้างอันใหม่
code เดิม


validates_file_format_of :image, :in => ["gif", "jpg", "png","pdf"]
file_column :image, :magick => {
   :versions => {
      :thumb => {:crop => "1:1", 
      :size => "50x50!", :name => "thumb"},
   }
}

ทุกไฟล์ที่ upload มันก็ทำ version ตามที่กำหนดไว้หมด แก้โดย


IMAGE_EXTENSIONS = {
"image/gif" => "gif",
"image/jpg" => "jpg",
"image/png" => "png"
}
OTHER_EXTENSIONS = {
"application/pdf" => "pdf",
"application/msword" => "doc",
"application/zip" => "zip",
"text/plain" => "txt",
"text/xml" => "xml",
"video/mpeg" => "mpeg",
"video/quicktime" => "mov",
}

file_column :image, :magick => {
   :options => {:mime_extensions => IMAGE_EXTENSIONS},
   :versions => {
      :thumb => {:crop => "1:1", 
      :size => "50x50!", :name => "thumb"},
   }
}

file_column( :image,
:options => {:mime_extensions => OTHER_EXTENSIONS})

ทำมันทั้งยังงี้ล่ะ เผื่อไฟล์อื่นจะได้ใช้ได้ด้วย ส่วน validates_file_format_of ก็เพื่มเอาเท่าที่ใช้

ไม่รู้ว่า act_as_attachment จะเป็นไงมั่ง แต่ตอนนี้สำหรับหผม file_column ยังโอเคอยู่

ที่มา

Posted by Revolution Thu, 08 Nov 2007 16:58:56 GMT

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

Rails Log

พอดีมีปัญหาเกี่ยวกับ log ใน rails ซึ่งมันก็กินเนื้อที่เยอะพอดูเลยพยามหาวิธีปิดมัน แต่สุดท้ายก็รู้ว่ามันปิดไม่ได้ เพราะ log มันเอาไว้ดูความเคลื่อนไหว ก็เลยได้แต่พยามหาวิธีให้มันเก็บน้อยลง ไปเจอที่ wiki ของ rails สรุปได้ว่า

ActiveRecord จะไปเรียกใช้ class Logger เพื่อจะทำการเก็บ log ลงไฟล์

ใน development จะใช้ :debug
ใน production จะใช้ :info

ซึ่งทั้งหมดก็มี :debug, :info, :warn, :error, :fatal ซึ่ง log class ของ ruby ยังมี :any แต่ไม่ทำงานบน rails ถ้าอยากให้ log น้อยลง เอาเฉพาะที่มี error ก็ใช้ :error

ให้เพิ่ม


config.log_level = :error

ลงในไฟล์

config/environment.rb

หรือถ้าจะปรับแต่งใดๆ ดูได้ที่ wiki ของ rails ครับ

Posted by Revolution Mon, 05 Nov 2007 04:15:14 GMT

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