Forum: Ruby on Rails RE: Re: log4r and rails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
William (Bill) Froelich (Guest)
on 2006-05-21 22:45
(Received via mailing list)
The first question I would ask (partially out of curiosity) is what
log4r specific feature are you trying to use?

While there are some neat log4r features, the built in logger provides
(from my perspective) a good logging framework already probably
addresses most logging needs.

http://wiki.rubyonrails.com/rails/pages/HowtoConfi...

That said, a basic setup to use log4r in rails follows a very similar
approach to using the built in logger.

Install the log4r gem

gem install log4r

Then edit your environment.rb file to use the gem and setup the logger

require "rubygems"
require "log4r"

#Setup Log4r Logging
L4R = Log4r::Logger.new("RailsLogging")
Log4r::FileOutputter.new('logfile',
                         :filename=>"#{RAILS_ROOT}/log/log4r.log",
                         :trunc=>false,
                         :level=>Log4r::DEBUG)
L4R.add('logfile')

Once you have the logger defined you can then make logging calls from
within your model, controllers and views

Model / Controller
------------------
L4R.debug "Debug message from Model or controller"


View
----
<% L4R.debug "Test debug from a view" %>

Hope this helps get you started.

--Bill
This topic is locked and can not be replied to.