<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>rob aldred &#187; custom</title>
	<atom:link href="http://robaldred.co.uk/tag/custom/feed/" rel="self" type="application/rss+xml" />
	<link>http://robaldred.co.uk</link>
	<description>cars, f1, bikes, tech tips &#38; what ever i&#039;m interested in this week</description>
	<lastBuildDate>Thu, 15 Apr 2010 13:54:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Custom log files for your ruby on rails applications</title>
		<link>http://robaldred.co.uk/2009/01/custom-log-files-for-your-ruby-on-rails-applications/</link>
		<comments>http://robaldred.co.uk/2009/01/custom-log-files-for-your-ruby-on-rails-applications/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 15:38:47 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://robaldred.co.uk/?p=27</guid>
		<description><![CDATA[Sometimes logging is required but putting the messages in the Rails log isn’t the answer.For example you need to see the progress of customers through your order placement cycle, you ideally need this seperate to any other in a custom log file? There is a solution and it&#8217;s easy&#8230; To create an order progress log, [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes logging is required but putting the messages in the Rails log isn’t the answer.For example you need to see the progress of customers through your order placement cycle, you ideally need this seperate to any other in a custom log file?</p>
<p>There is a solution and it&#8217;s easy&#8230; To create an order progress log, simply create a new instance of <em>Logger</em> and pass it a <em>File</em> instance for your own logfile.<br />
Create a new model which inherits from <em>Logger</em></p>
<pre lang="ruby">class OrderProgressLogger &lt; Logger
  def format_message(severity, timestamp, progname, msg)
  "#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
  end
end</pre>
<p>Create initializer called logs.rb in RAILS_ROOT/config/initializers with the following content:</p>
<pre lang="ruby">order_progress_logfile = File.open("#{RAILS_ROOT}/log/order_progress.log", 'a')
order_progress_logfile.sync = true
ORDER_PROGRESS_LOG = OrderProcessLogger.new(order_progress_logfile)</pre>
<p>After a restart of your mongrel or passenger <em>ORDER_PROGRESS_LOG</em> will be available through out your application.<br />
You log to it just as you would <em>DEFAULT_RAILS_LOGGER</em> like so&#8230;</p>
<pre lang="ruby">ORDER_PROGRESS_LOG.debug "Starting order placement method"
ORDER_PROGRESS_LOG.error "Could not create order record"</pre>
]]></content:encoded>
			<wfw:commentRss>http://robaldred.co.uk/2009/01/custom-log-files-for-your-ruby-on-rails-applications/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
