I can''t use @logger in a controller, so that would imply that I can''t in a view, either. But I _can_ use @logger in a view. Confusing. I _can_ use logger in a controller, but not in a view. And I can use RAILS_DEFAULT_LOGGER in either. Summing up: Controller View @logger - X logger X - R_D_L X X That must be made more consistent. When I asked about this on IRC, I was told that logging was one of the most frequently asked questions about Rails. Furthermore, ''logger'' should be a method (how it could possibly be a local variable as Jarkko suggests boggles me) that''s visible in the API docs. (Thinking about it, logger is probably a protected method in ActionController::Base, so it can''t be used as an action. Protected methods can be made to appear in the RDoc output with a ":doc:" modifier. Gavin On Thursday, April 21, 2005, 2:53:19 AM, Ben wrote:> You can, also, use @logger in view, IIRC. It''s all a matter of > scoping, but it''s a class variable that Rails magically turns into an > instance variable for views.> On 4/20/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote: >> >> On 20.4.2005, at 19:05, Gavin Sinclair wrote: >> >> > On Thursday, April 21, 2005, 12:48:40 AM, Thomas wrote: >> > >> >> http://wiki.rubyonrails.com/rails/show/HowtoAccessTheLogFile >> > >> >> might have some answers for you. >> > >> > Nope. Doesn''t address the absence of ''logger'' in the API doc methods >> > frame, or the fact that you can''t use it in a view/helper. >> >> It''s not a method, it''s a local variable representing a Logger object. >> Other than that, the wiki page pretty well explains how to use it. It >> should be possible to use RAILS_DEFAULT_LOGGER from views. Haven''t >> tested that, tho. >> >> //jarkko
On Thursday, April 21, 2005, 1:27:23 PM, Gavin wrote:> Summing up:> Controller View Model > @logger - X - > logger X - X > R_D_L X X X(Just added test results for model...)
On 21.4.2005, at 06:27, Gavin Sinclair wrote:> Furthermore, ''logger'' should be a method (how it could possibly be a > local variable as Jarkko suggests boggles me) that''s visible in the > API docs.Sorry Gavin, I was wrong. It''s a class variable in ActionController::Base and also an accessor method to that variable, thus the naming convention. (see line #236 of lib/action_controller/base.rb): cattr_accessor :logger Cattr_Accessor is defined in activesupport/lib/active_support/class_attribute_accessors.rb //jarkko> > (Thinking about it, logger is probably a protected method in > ActionController::Base, so it can''t be used as an action. Protected > methods can be made to appear in the RDoc output with a ":doc:" > modifier. > > Gavin > > > On Thursday, April 21, 2005, 2:53:19 AM, Ben wrote: > >> You can, also, use @logger in view, IIRC. It''s all a matter of >> scoping, but it''s a class variable that Rails magically turns into an >> instance variable for views. > >> On 4/20/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote: >>> >>> On 20.4.2005, at 19:05, Gavin Sinclair wrote: >>> >>>> On Thursday, April 21, 2005, 12:48:40 AM, Thomas wrote: >>>> >>>>> http://wiki.rubyonrails.com/rails/show/HowtoAccessTheLogFile >>>> >>>>> might have some answers for you. >>>> >>>> Nope. Doesn''t address the absence of ''logger'' in the API doc >>>> methods >>>> frame, or the fact that you can''t use it in a view/helper. >>> >>> It''s not a method, it''s a local variable representing a Logger >>> object. >>> Other than that, the wiki page pretty well explains how to use it. It >>> should be possible to use RAILS_DEFAULT_LOGGER from views. Haven''t >>> tested that, tho. >>> >>> //jarkko > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Gavin Sinclair <gsinclair-81uBx+iSpXA0n/F98K4Iww@public.gmane.org> writes:>> Summing up: > >> Controller View Model >> @logger - X - >> logger X - X >> R_D_L X X XLooking at this makes me wonder how "we" could add access to the logger method in the view. That would be the simplest and most consistent solution. The config/environment.rb makes it clear how the logger method gets defined: [ActiveRecord, ActionController, ActionMailer].each { |mod| mod::Base.logger ||= RAILS_DEFAULT_LOGGER } So it seems as simple as knowing what object''s scope the view is evaluated in and adding it to this list. My assumption is that it''s ActionView. -- doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org
There''s one way to find out. Just add "cattr_accessor :logger" to the definition of the ActiveView::Base class and add it to that array. I''m betting it will work, but how often do people really log from Views? Isn''t the point of a view to display the information grokked in Controllers & Models? Most transformation should have taken place, so it seems unlikely (to me, anyway) that''d you need to do much logging there. Just trying to understand. Ben On 4/21/05, Doug Alcorn <doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org> wrote:> Gavin Sinclair <gsinclair-81uBx+iSpXA0n/F98K4Iww@public.gmane.org> writes: > > >> Summing up: > > > >> Controller View Model > >> @logger - X - > >> logger X - X > >> R_D_L X X X > > Looking at this makes me wonder how "we" could add access to the > logger method in the view. That would be the simplest and most > consistent solution. > > The config/environment.rb makes it clear how the logger method gets > defined: > > [ActiveRecord, ActionController, ActionMailer].each { |mod| mod::Base.logger ||= RAILS_DEFAULT_LOGGER } > > So it seems as simple as knowing what object''s scope the view is > evaluated in and adding it to this list. My assumption is that it''s > ActionView. > -- > doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Friday, April 22, 2005, 2:04:30 AM, Ben wrote:>> >> Summing up: >> > >> >> Controller View Model >> >> @logger - X - >> >> logger X - X >> >> R_D_L X X X >> >> Looking at this makes me wonder how "we" could add access to the >> logger method in the view. That would be the simplest and most >> consistent solution.> There''s one way to find out. Just add "cattr_accessor :logger" to the > definition of the ActiveView::Base class and add it to that array. I''m > betting it will work, but how often do people really log from Views? > Isn''t the point of a view to display the information grokked in > Controllers & Models? Most transformation should have taken place, so > it seems unlikely (to me, anyway) that''d you need to do much logging > there.Personally, I would very rarely log from a view itself, but frequently log from a helper method, which (IIUC) behaves like a view in this matter. Gavin
Gavin Sinclair wrote:> On Friday, April 22, 2005, 2:04:30 AM, Ben wrote: >>There''s one way to find out. Just add "cattr_accessor :logger" to the >>definition of the ActiveView::Base class and add it to that array. I''m >>betting it will work, but how often do people really log from Views? >>Isn''t the point of a view to display the information grokked in >>Controllers & Models? Most transformation should have taken place, so >>it seems unlikely (to me, anyway) that''d you need to do much logging >>there. > > Personally, I would very rarely log from a view itself, but frequently > log from a helper method, which (IIUC) behaves like a view in this > matter.To expose the controller''s logger to its views, including helper methods: class ApplicationController < ActionController::Base helper_method :logger end jeremy