So I want to log some information in development.log. Q: How do I access the default log file? A: (from IRC a week ago) logger.debug "message" (or logger.info/warn/...) Follow up question: ''logger'' must be a method, right? Why doesn''t it appear in the methods pane of the API docs? Also, why is ''logger'' available to controllers and not to views?
http://wiki.rubyonrails.com/rails/show/HowtoAccessTheLogFile might have some answers for you. -- Thomas Am 20.04.2005 um 16:27 schrieb Gavin Sinclair:> So I want to log some information in development.log. > > Q: How do I access the default log file? > A: (from IRC a week ago) logger.debug "message" (or > logger.info/warn/...) > > Follow up question: > > ''logger'' must be a method, right? Why doesn''t it appear in the > methods pane of the API docs? > > Also, why is ''logger'' available to controllers and not to views? > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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. Gavin
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> > Gavin > > _______________________________________________ > 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
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 > > > > > Gavin > > > > _______________________________________________ > > 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 > > > >
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 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. I''m just guessing, but isn''t it an object, not a method? It is probably only in scope in the controller. - -- David Morton Maia Mailguard server side anti-spam/anti-virus solution: http://www.maiamailguard.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCZtNkSIxC85HZHLMRAi9kAJ41ooCGslOySSMJNYcs8jJBGtQvjQCdG6Tn fz0+6VB+r/RWM4xG2CgVSdQ=Dp30 -----END PGP SIGNATURE-----
On Thursday, April 21, 2005, 8:10:45 AM, David wrote:> | 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.> I''m just guessing, but isn''t it an object, not a method?> It is probably only in scope in the controller.When you have a snippet of code that says class SomeController < ApplicationController def some_action logger.info "In some_action..." end end the "logger" is either a local variable or a method. It can''t be a variable that''s only in scope in the controller -- that would be @logger, @@logger, or LOGGER. If it''s a local variable, it''s local to the some_action method, and there''s no Ruby magic I know of that can create a local variable in a method behind the scenes. It''s reasonable to conclude, then, that it''s a method which returns a Logger object. That method could be in the SomeController class, in a super class (ApplicationController or ActionController::Base), or a module that got mixed in along the way. Hope that''s useful to know :) Cheers, Gavin
Technically, Gavin, since it''s added with cattr_accessor, it''s really a class variable that is assigned a value in config/environments.rb. Don''t just assume things are the way you think they ought to be without investigating. Hope that''s useful to know. Ben On 4/20/05, Gavin Sinclair <gsinclair-81uBx+iSpXA0n/F98K4Iww@public.gmane.org> wrote:> On Thursday, April 21, 2005, 8:10:45 AM, David wrote: > > > | 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. > > > I''m just guessing, but isn''t it an object, not a method? > > > It is probably only in scope in the controller. > > When you have a snippet of code that says > > class SomeController < ApplicationController > def some_action > logger.info "In some_action..." > end > end > > the "logger" is either a local variable or a method. It can''t be a > variable that''s only in scope in the controller -- that would be > @logger, @@logger, or LOGGER. > > If it''s a local variable, it''s local to the some_action method, and > there''s no Ruby magic I know of that can create a local variable in a > method behind the scenes. > > It''s reasonable to conclude, then, that it''s a method which returns a > Logger object. That method could be in the SomeController class, in a > super class (ApplicationController or ActionController::Base), or a > module that got mixed in along the way. > > Hope that''s useful to know :) > > Cheers, > Gavin > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Incorrect. "logger" is not a class variable; it''s a method that accesses a class variable. @@logger or @logger is the class variable. It''s a very important distinction. (BTW, "logger=" is a method as well.) I call on years of Ruby experience to assume things are the way I think they are. Furthermore, I actively avoid looking at the code for issues like this: I''m trying to raise questions that will result in the improvement of the framework or the documentation, whichever is appropriate. Answering my own question will probably leave the matter unresolved until someone else asks it and follows through. Gavin On Friday, April 22, 2005, 1:56:45 AM, Ben wrote:> Technically, Gavin, since it''s added with cattr_accessor, it''s really > a class variable that is assigned a value in config/environments.rb. > Don''t just assume things are the way you think they ought to be > without investigating.> Hope that''s useful to know.> Ben> On 4/20/05, Gavin Sinclair <gsinclair-81uBx+iSpXA0n/F98K4Iww@public.gmane.org> wrote: >> On Thursday, April 21, 2005, 8:10:45 AM, David wrote: >> >> > | 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. >> >> > I''m just guessing, but isn''t it an object, not a method? >> >> > It is probably only in scope in the controller. >> >> When you have a snippet of code that says >> >> class SomeController < ApplicationController >> def some_action >> logger.info "In some_action..." >> end >> end >> >> the "logger" is either a local variable or a method. It can''t be a >> variable that''s only in scope in the controller -- that would be >> @logger, @@logger, or LOGGER. >> >> If it''s a local variable, it''s local to the some_action method, and >> there''s no Ruby magic I know of that can create a local variable in a >> method behind the scenes. >> >> It''s reasonable to conclude, then, that it''s a method which returns a >> Logger object. That method could be in the SomeController class, in a >> super class (ApplicationController or ActionController::Base), or a >> module that got mixed in along the way. >> >> Hope that''s useful to know :) >> >> Cheers, >> Gavin