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!

-- time_stamp:datetime, :progname:string, msg:string ++ time_stamp:datetime, progname:string, msg:string
Tnx :P, Small typo that slipped in
Well, the initial idea was good :)