jgeiger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-23 18:36 UTC
Rails logger.silence on controller action
I''ve got a simple controller which is being hit every minute to monitor the website. I''ve read in a few places, and on this group as well that if you include a logger.silence around the code, it shouldn''t appear in the log. With the controller below, I get log entries every time the action is called. I''m just wondering what I may be doing wrong. Thanks. CONTROLLER: class MonitController < ActionController::Base session :off ## this is used by the monitoring scripts to see if the mongrel is up and running def index logger.silence do render :text => ''success'' end end end LOG OUTPUT: Processing MonitController#index (for 127.0.0.1 at 2007-01-23 12:18:45) [GET] Parameters: {"action"=>"index", "controller"=>"monit"} Completed in 0.00349 (286 reqs/sec) | Rendering: 0.00007 (2%) | DB: 0.00000 (0%) | 200 OK [http:// /monit/index] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Just wondering if any solution was found for this - I''m in exactly the same position, looking to suppress Monit actions from appearing in my log. Wrapping the action in logger.silence seems to have no effect, nor does forcibly increasing the logger.level to try and filter it out. I''m on Rails 1.1.6 - is it perhaps a 1.2+ thing only? Cheers, Mike On Jan 23, 6:36 pm, "jgei...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <jgei...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve got a simple controller which is being hit every minute to monitor > the website. I''ve read in a few places, and on this group as well that > if you include a logger.silence around the code, it shouldn''t appear in > thelog. With the controller below, I getlogentries every time theactionis called. I''m just wondering what I may be doing wrong. > > Thanks. > > CONTROLLER: > class MonitController < ActionController::Base > session :off > ## this is used by the monitoring scripts to see if the mongrel is up > and running > def index > logger.silence do > render :text => ''success'' > end > end > end > > LOGOUTPUT: > Processing MonitController#index (for 127.0.0.1 at 2007-01-23 12:18:45) > [GET] > Parameters: {"action"=>"index", "controller"=>"monit"} > Completed in 0.00349 (286 reqs/sec) | Rendering: 0.00007 (2%) | DB: > 0.00000 (0%) | 200 OK [http:// /monit/index]--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Doesn''t appear to be (even in 1.2+), other than monkey patching ActionController::Base#log_processing for your needs. If you''re doing this to see if Mongrel is up, why not write a simple handler and place it in config/mongrel.conf? This won''t get logged anywhere, and is way faster than going to rails for it: # lib/monit_handler.rb class MonitHandler < Mongrel::HttpHandler def process(request, response) response.start { |head, out| out.write("I''m up...") } end end # config/mongrel.conf uri "/monit", :handler => MonitHandler.new Then in your production scripts, you need to pass in an extra switch to mongrel so it''ll use config/mongrel.conf. If you''re using mongrel cluster, add: config_script: config/mongrel.conf to your config/mongrel_cluster.yml On Mar 20, 5:27 am, "Mike Evans" <m...-0oKK9m5UmnmZEsiFbgKFjg@public.gmane.org> wrote:> Just wondering if any solution was found for this - I''m in exactly the > same position, looking to suppress Monit actions from appearing in my > log. Wrapping the action in logger.silence seems to have no effect, > nor does forcibly increasing the logger.level to try and filter it > out. > > I''m on Rails 1.1.6 - is it perhaps a 1.2+ thing only? > > Cheers, > Mike > > On Jan 23, 6:36 pm, "jgei...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <jgei...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''ve got a simple controller which is being hit every minute to monitor > > the website. I''ve read in a few places, and on this group as well that > > if you include a logger.silence around the code, it shouldn''t appear in > > thelog. With the controller below, I getlogentries every time theactionis called. I''m just wondering what I may be doing wrong. > > > Thanks. > > > CONTROLLER: > > class MonitController < ActionController::Base > > session :off > > ## this is used by the monitoring scripts to see if the mongrel is up > > and running > > def index > > logger.silence do > > render :text => ''success'' > > end > > end > > end > > > LOGOUTPUT: > > Processing MonitController#index (for 127.0.0.1 at 2007-01-23 12:18:45) > > [GET] > > Parameters: {"action"=>"index", "controller"=>"monit"} > > Completed in 0.00349 (286 reqs/sec) | Rendering: 0.00007 (2%) | DB: > > 0.00000 (0%) | 200 OK [http:// /monit/index]--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
jgeiger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-24 21:15 UTC
Re: Rails logger.silence on controller action
I did find a way around it. Putting a def logger end in the controller short circuits the logger from running and nothing is ever written to the log files. This has also had the added benefit of removing a large amount of memory usage for my application over time. Also, I thought about going the mongrel handler route, but this works for now. CONTROLLER: class MonitController < ActionController::Base session :off ## this is used by the monitoring scripts to see if the mongrel is up and running def index end def logger end end On Mar 19, 11:53 pm, "eden li" <eden...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Doesn''t appear to be (even in 1.2+), other than monkey patching > ActionController::Base#log_processing for your needs. > > If you''re doing this to see if Mongrel is up, why not write a simple > handler and place it in config/mongrel.conf? This won''t get logged > anywhere, and is way faster than going to rails for it: > > # lib/monit_handler.rb > class MonitHandler < Mongrel::HttpHandler > def process(request, response) > response.start { |head, out| out.write("I''m up...") } > end > end > > # config/mongrel.conf > uri "/monit", :handler => MonitHandler.new > > Then in your production scripts, you need to pass in an extra switch > to mongrel so it''ll use config/mongrel.conf. If you''re using mongrel > cluster, add: > > config_script: config/mongrel.conf > > to your config/mongrel_cluster.yml > > On Mar 20, 5:27 am, "Mike Evans" <m...-0oKK9m5UmnmZEsiFbgKFjg@public.gmane.org> wrote: > > > Just wondering if any solution was found for this - I''m in exactly the > > same position, looking to suppress Monit actions from appearing in my > > log. Wrapping the action in logger.silenceseems to have no effect, > > nor does forcibly increasing the logger.level to try and filter it > > out. > > > I''m on Rails 1.1.6 - is it perhaps a 1.2+ thing only? > > > Cheers, > > Mike > > > On Jan 23, 6:36 pm, "jgei...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <jgei...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I''ve got a simple controller which is being hit every minute to monitor > > > the website. I''ve read in a few places, and on this group as well that > > > if you include a logger.silencearound the code, it shouldn''t appear in > > > thelog. With the controller below, I getlogentries every time theactionis called. I''m just wondering what I may be doing wrong. > > > > Thanks. > > > > CONTROLLER: > > > class MonitController < ActionController::Base > > > session :off > > > ## this is used by the monitoring scripts to see if the mongrel is up > > > and running > > > def index > > > logger.silencedo > > > render :text => ''success'' > > > end > > > end > > > end > > > > LOGOUTPUT: > > > Processing MonitController#index (for 127.0.0.1 at 2007-01-23 12:18:45) > > > [GET] > > > Parameters: {"action"=>"index", "controller"=>"monit"} > > > Completed in 0.00349 (286 reqs/sec) | Rendering: 0.00007 (2%) | DB: > > > 0.00000 (0%) | 200 OK [http:// /monit/index]--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---