Hi, How I print a text in the consile?? I want use this for debug, only, to trace some variables, and the "puts" don''t works, why? Thank you -- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
Use "warn" instead of "puts" Warn writes to stderr (I believe) which goes to the console instead of to the web browser. Dave On 4/25/05 2:53 PM, "Pedro Valentini" <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:> > Hi, > How I print a text in the consile?? > I want use this for debug, only, to trace some variables, and the "puts" > don''t works, why? > > Thank you
Thank you! You are right. Do you use it to debug? (warn) Pedro Dave Ringoen escreveu:>Use "warn" instead of "puts" > >Warn writes to stderr (I believe) which goes to the console instead of to >the web browser. > >Dave > > >On 4/25/05 2:53 PM, "Pedro Valentini" <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: > > > >>Hi, >>How I print a text in the consile?? >>I want use this for debug, only, to trace some variables, and the "puts" >>don''t works, why? >> >>Thank you >> >> > > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > >-- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
On 4/26/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:> > Thank you! > You are right. > Do you use it to debug? (warn)You''re probably better off using the logger methods. For instance: logger.info "some message" This will, by default, result in a message being appended to log/<environment>.log. That way you can leave the console for the access_log of webrick. My typical development environment involves three terminal windows, one for webrick, one for tail -f log/development.log and another for running random commands. Some others may add a breakpoint console to that, but I''m with Brian Kernighan on debuggers: "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian Kernighan> Pedro > > Dave Ringoen escreveu: > > >Use "warn" instead of "puts" > > > >Warn writes to stderr (I believe) which goes to the console instead of to > >the web browser. > > > >Dave > > > > > >On 4/25/05 2:53 PM, "Pedro Valentini" <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: > > > > > > > >>Hi, > >>How I print a text in the consile?? > >>I want use this for debug, only, to trace some variables, and the "puts" > >>don''t works, why? > >> > >>Thank you > >> > >> > > > > > >_______________________________________________ > >Rails mailing list > >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > -- > > Pedro C. Valentini > pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org > +55 (21) 8708-8035 > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz
Michael Koziarski wrote:> On 4/26/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: >>Thank you! >>You are right. >>Do you use it to debug? (warn) > > You''re probably better off using the logger methods. For instance: > > logger.info "some message" > > This will, by default, result in a message being appended to > log/<environment>.log. That way you can leave the console for the > access_log of webrick.A neat hack could replace $stdout and $stderr with objects that write to a logger instead: class LoggerIO def initialize(logger, level = Logger::INFO) @logger, @level = logger, level end def log(*messages) messages.flatten.each { |m| @logger.log(@level, m) } end [:<<, :puts, :print].each { |method| alias_method method, :log } private def method_missing(*args, &block) # Cheers for dangerous ignorance. end end $stdout = LoggerIO.new(ActionController::Base.logger, Logger::INFO) $stderr = LoggerIO.new(ActionController::Base.logger, Logger::ERROR) But that would encourage code with bad smell and be so wrong ;-) jeremy