<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: logger code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Wed, 23 Jul 2008 12:02:05 GMT</pubDate>
    <description>DZone Snippets: logger code</description>
    <item>
      <title>Watir Logging</title>
      <link>http://snippets.dzone.com/posts/show/5218</link>
      <description>// setup logging infrastructure for Watir tests using ruby Logger class&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#Logging infrastructure&lt;br /&gt;require 'logger'&lt;br /&gt;# hack ruby logger to format and output only the minimum needed for testing scripts&lt;br /&gt;# Logger is configured to write &lt;br /&gt;class Logger&lt;br /&gt;  # hack format of logger&lt;br /&gt;  class Formatter&lt;br /&gt;    #original: Format = "%s, [%s#%d] %5s -- %s: %s\n"&lt;br /&gt;    #Change the name of constant to avoid redefining the super which raises exception and bugs us.&lt;br /&gt;    Formato = "[%s] [%5s] : %s\n" &lt;br /&gt;    &lt;br /&gt;    #keep the original signature but alter implementation to change formatting&lt;br /&gt;    def call(severity, time, progname, msg)&lt;br /&gt;      #add logging to stdout&lt;br /&gt;      puts output_message = msg2str(msg)&lt;br /&gt;      STDOUT.flush&lt;br /&gt;      #original: Format % [severity[0..0], format_datetime(time), $$, severity, progname, msg2str(msg)]&lt;br /&gt;      Formato % [format_datetime(time),severity, output_message]&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;logfile = File.join(File.dirname(__FILE__),'..','log', 'logger.log')&lt;br /&gt;$log = Logger.new(logfile,'daily')&lt;br /&gt;$log.level = Logger::DEBUG&lt;br /&gt;$log.datetime_format = "%H:%M:%S"&lt;br /&gt;$log.info("Watir Execution Starts")&lt;br /&gt;$log.debug("Halllow Worled!")&lt;br /&gt;$log.info("Achtung Achtung. The Train will leave from platform 9")&lt;br /&gt;$log.warn("no no no no no. you can't do this")&lt;br /&gt;$log.error("error error Danger Danger")&lt;br /&gt;$log.fatal("game over game over game over")&lt;br /&gt;# example of output&lt;br /&gt;#[13:02:00] [DEBUG] : Watir Execution Starts&lt;br /&gt;#[13:02:00] [DEBUG] : Halllow Worled!&lt;br /&gt;#[13:02:00] [ INFO] : Achtung Achtung. The Train will leave from platform 9&lt;br /&gt;#[13:02:00] [ WARN] : no no no no no. you can't do this&lt;br /&gt;#[13:02:00] [ERROR] : error error Danger Danger&lt;br /&gt;#[13:02:00] [FATAL] : game over game over game over&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 12 Mar 2008 18:05:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5218</guid>
      <author>marekj (marekj)</author>
    </item>
    <item>
      <title>How to rotate your Rails logs by size, so you can allocate a certain amount of space for it.</title>
      <link>http://snippets.dzone.com/posts/show/979</link>
      <description>Add this to RAILS_ROOT/config/environment.rb to keep 50 logfiles of 1MB each.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;config.logger = Logger.new("#{RAILS_ROOT}/log/#{ENV['RAILS_ENV']}.log", 50, 1048576)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 15 Dec 2005 10:34:35 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/979</guid>
      <author>procreate (Charles M. Gerungan)</author>
    </item>
  </channel>
</rss>
