Hello, I whish configure logger, adding a prefix in all "logger.error(..)", a prefix like "ERROR------------------>", to be able, then to search in log file, easily. And to do that I had the idea of reopen Logger class, like this: - In a file placed in \initializers\ I put def initialize(args=nil) super(args) end def error(msg) super("ERROR------------>"+msg) end end But this doesn''t do anything, ¿ where do I have to put this code ? - And if I put in config/environments/development.rb config.logger = Logger.new(STDOUT) raises an error: [super: no superclass method `error'' for #<Logger:0x3d7bae8>] Could someone guide me for the right way? I''m absolutly lost. What does usually people do to look for in the "great" production.log file? I know, if I put config.log_level = :warn, this file would be thin, but I supose than this "info" messages are important to understand the whole error. Thanks a lot. -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2011/2/1 Albert Català <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> I whish configure logger, adding a prefix in all "logger.error(..)", a > prefix like "ERROR------------------>", to be able, then to search in > log file, easily.> Could someone guide me for the right way? I''m absolutly lost.I don''t know about the "right" way :-) but I wanted timestamps for one of my apps, so put this in my application_controller.rb : class ActiveSupport::BufferedLogger SEVERITIES = { 0 => ''DEBUG'', 1 => ''INFO'', 2 => ''WARN'', 3 => ''ERROR'', 4 => ''FATAL'', 5 => ''UNKNOWN'' } unless defined?(SEVERITIES) def add(severity, message = nil, progname = nil, &block) return if @level > severity message = (message || (block && block.call) || progname).to_s message = "#{Time.current.getlocal.strftime(''%F-%H:%M:%S'')} #{SEVERITIES[severity]} #{message}\n" unless message[-1] == ?\n buffer << message auto_flush message end end There certainly could be other ways, but this works. HTH! -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
¿ Is this solution accessible from Models ? "logger ("...") in a model, ¿reach this code ( class ActiveSupport::BufferedLogger)? thanks you I like this solution (http://railscasts.com/episodes/56-the-logger) in environment.rb: class Logger def format_message(level, time, progname, msg) "#{time.to_s(:db)} #{level} -- #{msg}\n" end end It seems easy , but I can''t do it working for Rails 3. -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2011/2/2 Albert Català <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> ¿ Is this solution accessible from Models ? "logger ("...") in a model, > ¿reach this code ( class ActiveSupport::BufferedLogger)?I have logging in models, yes, and it works fine (at least on 2.3.x).> I like this solution (http://railscasts.com/episodes/56-the-logger)> It seems easy , but I can''t do it working for Rails 3.Sorry, haven''t tried to convert this app yet :-) -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2011/2/1 Albert Català <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> Hello, > I whish configure logger, adding a prefix in all "logger.error(..)", a > prefix like "ERROR------------------>", to be able, then to search in > log file, easily. > > And to do that I had the idea of reopen Logger class, like this: > > - In a file placed in \initializers\ I put > > def initialize(args=nil) > super(args) > end# you want to put it in as a class method class << self> def error(msg) > super("ERROR------------>"+msg) > endend # class methods Object.method_name> end > > But this doesn''t do anything, ¿ where do I have to put this code ? > > - And if I put in config/environments/development.rb > > config.logger = Logger.new(STDOUT) > > raises an error: [super: no superclass method `error'' for > #<Logger:0x3d7bae8>] > > Could someone guide me for the right way? I''m absolutly lost. > > What does usually people do to look for in the "great" production.log > file? > > I know, if I put config.log_level = :warn, this file would be thin, but > I supose than this "info" messages are important to understand the whole > error. > > Thanks a lot. > > -- > Posted via http://www.ruby-forum.com/. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- make haste slowly \ festina lente \ - mobile +1_415_632_6001 curtis-DDU1nqEjlGkHaT8GDLgCUg@public.gmane.org http://robotarmyma.de -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2011/2/1 Albert Català <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> Hello, > I whish configure logger, adding a prefix in all "logger.error(..)", a > prefix like "ERROR------------------>", to be able, then to search in > log file, easily. > > And to do that I had the idea of reopen Logger class, like this: > > - In a file placed in \initializers\ I put > > def initialize(args=nil) > super(args) > end > def error(msg)#also - this may give you an error # i remember this as msg = %%ERROR#{''-''*5}>#{msg}% super> super("ERROR------------>"+msg) > end > end > > But this doesn''t do anything, ¿ where do I have to put this code ? > > - And if I put in config/environments/development.rb > > config.logger = Logger.new(STDOUT) > > raises an error: [super: no superclass method `error'' for > #<Logger:0x3d7bae8>] > > Could someone guide me for the right way? I''m absolutly lost. > > What does usually people do to look for in the "great" production.log > file? > > I know, if I put config.log_level = :warn, this file would be thin, but > I supose than this "info" messages are important to understand the whole > error. > > Thanks a lot. > > -- > Posted via http://www.ruby-forum.com/. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- make haste slowly \ festina lente \ - mobile +1_415_632_6001 curtis-DDU1nqEjlGkHaT8GDLgCUg@public.gmane.org http://robotarmyma.de -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Curtis j Schofield wrote in post #979342:> 2011/2/1 Albert Catal <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>: >> super(args) >> end >> def error(msg) > > #also - this may give you an error > # i remember this as > msg = %%ERROR#{''-''*5}>#{msg}% > super > >> raises an error: [super: no superclass method `error'' for >> >> >>What I did, exactly is: class Logger def initialize(args=nil) super(args) end def error(msg) super("ERROR------------>"+msg) end end this is in a file.rb in config/initializers/ and raises the error I said -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 3, 10:57 am, Albert Català <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Curtis j Schofield wrote in post #979342:> 2011/2/1 Albert Catal <li...@ruby-forum.com>: > >> super(args) > >> end > >> def error(msg) > > > #also - this may give you an error > > # i remember this as > > msg = %%ERROR#{''-''*5}>#{msg}% > > super > > >> raises an error: [super: no superclass method `error'' for > > What I did, exactly is: > class Logger > def initialize(args=nil) > super(args) > end > def error(msg) > super("ERROR------------>"+msg) > end > end > > this is in a file.rb in config/initializers/ > > and raises the error I said >This fails because the superclass of Logger doesn''t have an error method - it''s Logger itself that provides it. Either have your class subclass from Logger and set your application to use that logger class, or alias the error method and instead of calling the super call the aliased name (depending on how the class is setup there''s also a trick you can play with modules) Fred> -- > Posted viahttp://www.ruby-forum.com/.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 3, 2011, at 2:57 AM, Albert Català <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Curtis j Schofield wrote in post #979342: >> 2011/2/1 Albert Catal <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>: >>> super(args) >>> end >>> def error(msg) >> >> #also - this may give you an error >> # i remember this as >> msg = %%ERROR#{''-''*5}>#{msg}% >> super >> >>> raises an error: [super: no superclass method `error'' for >>> >>> >>> > What I did, exactly is: > class Logger > def initialize(args=nil) > super(args) > end > def error(msg) > super("ERROR------------>"+msg) > end > end > > this is in a file.rb in config/initializers/ > > and raises the error I said >Did you read my other response about class methods?> -- > Posted via http://www.ruby-forum.com/. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Curtis wrote in post #979429:> On Feb 3, 2011, at 2:57 AM, Albert Catal <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >>> >> super("ERROR------------>"+msg) >> end >> end >> >> this is in a file.rb in config/initializers/ >> >> and raises the error I said >> > > > > Did you read my other response about class methods?Yes but I''m still truing to do that, what do you mean? with class << self> def error(msg) > super("ERROR------------>"+msg) > endend # class methods Object.method_name and where do I have to put this code? Thanks for patience -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 3, 2011, at 2:16 PM, Albert Català <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Curtis wrote in post #979429: >> On Feb 3, 2011, at 2:57 AM, Albert Catal <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> >> wrote: >> >>>> >>> super("ERROR------------>"+msg) >>> end >>> end >>> >>> this is in a file.rb in config/initializers/ >>> >>> and raises the error I said >>> >> >> >> >> Did you read my other response about class methods? > > Yes but I''m still truing to do that, what do you mean? with > > class << self >> def error(msg) >> super("ERROR------------>"+msg) >> end > end # class methods Object.method_name > > and where do I have to put this code? > > Thanks for patienceHey no worries - so class A def self.error(msg) #comment - class method ''error'' end end your first post had the right idea - only error is a method that belongs to the Logger instance - not the dynamic instance. In A I have a method ''error'' that belongs to the A instance. A.new.error Would result in a NoMethod on the execution of the code. class A def error end end A.new.error Will work now. You can try this in irb. You original code had a method that would go on a new instance of Logger - what you needed was a method ''error'' on the Logger instance ( refered to in object oriented programming as a the Logger Class) When the error mentioned that the method could not be found - it is because the ''super'' version of the method is actually in Logger the class method error . Logger.info "assuming we are talking about the same logger•" -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks for your time, but i am not able to make this working. Where can I see the code, and the files (if conig/application.rb. or where ever is), than explain how to customize the logger? thanks again (I am new in Ruby but not in Visual Foxpro, if somebody needs my help, I can exchange knowledge) -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.