Forum: Ruby on Rails Logging - using a different log for one method

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.
Tim H. (Guest)
on 2009-04-30 11:12
(Received via mailing list)
Hi there,

I'm wondering if there's a way to have any log statements generated
from a specific method on a model get logged into a separate file from
the normal development/production log files?

i.e. I want the whole app to log as normal, apart from the
Sprinter.run_often method, which I'd like to log to
sprinter_running.log

Cheers,

Tim.
Ivan P. (Guest)
on 2009-04-30 11:58
(Received via mailing list)
I guess it would be something like

sprinter_log = BufferedLogger.new("sprinter_runner.log")

sprinter_log.log('yay I'm logging')
Tim H. (Guest)
on 2009-04-30 12:10
(Received via mailing list)
Hi Ivan,

Thanks - I thought I was probably missing a detail.  That will put my
own log statements into a new log.  But what I'm aiming for is to get
AR generated log statements into the separate log file also.  Without
interfering with whatever other code is running concurrently.

Cheers,

Tim.
Ivan P. (Guest)
on 2009-04-30 12:20
(Received via mailing list)
Monkey patch ActiveRecord::Base or your base class and override logger

def logger
  @logger = BufferedLogger.new('name')

end
This topic is locked and can not be replied to.