<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Moves On Rails: Tag format_message</title>
    <link>http://www.movesonrails.com/articles/tag/format_message?tag=format_message</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>New ways to look at software</description>
    <item>
      <title>Building a database logger</title>
      <description>&lt;p&gt;Sometimes you don't want to log to a file, but to your database. A quick and somewhat dirty way for this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; script/generate scaffold_resource LogEntry severity:string, \
  time_stamp:datetime, progname:string, msg:string
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With the following logger:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class MovesLogger &amp;lt; Logger

  def format_message(severity, timestamp, progname, msg)
    logEntry = LogEntry.new({:severity  =&amp;gt;  severity,
                           :timestamp  =&amp;gt;  timestamp,
                           :progname   =&amp;gt;  progname, 
                           :msg        =&amp;gt;  msg})
    logEntry.save
    return nil
  end  
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now you can use logger = MovesLogger.new($stdout) and everything will be neatly logged to the database!&lt;/p&gt;</description>
      <pubDate>Wed, 18 Jul 2007 09:26:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:a8352775-bbfa-432d-ac50-806195458c9f</guid>
      <author>bart.tenbrinke@movesonrails.com (Bart ten Brinke)</author>
      <link>http://www.movesonrails.com/articles/2007/07/18/building-a-database-logger</link>
      <category>Ruby</category>
      <category>ruby</category>
      <category>Logger</category>
      <category>format_message</category>
      <category>database</category>
    </item>
  </channel>
</rss>
