Building a database logger

Posted by Bart ten Brinke Wed, 18 Jul 2007 07:30:38 GMT

Sometimes you don't want to log to a file, but to your database. A quick and somewhat dirty way for this:

 script/generate scaffold_resource LogEntry severity:string, \
  time_stamp:datetime, progname:string, msg:string

With the following logger:

class MovesLogger < Logger

  def format_message(severity, timestamp, progname, msg)
    logEntry = LogEntry.new({:severity  =>  severity,
                           :timestamp  =>  timestamp,
                           :progname   =>  progname, 
                           :msg        =>  msg})
    logEntry.save
    return nil
  end  
end

Now you can use logger = MovesLogger.new($stdout) and everything will be neatly logged to the database!

Comments

  1. LeipeLeon said 8 days later:
    -- time_stamp:datetime, :progname:string, msg:string ++ time_stamp:datetime, progname:string, msg:string
  2. Andre Foeken said 11 days later:
    Tnx :P, Small typo that slipped in
  3. Bart ten Brinke said 20 days later:
    Well, the initial idea was good :)

(leave url/email »)

   Preview comment