I was playing with the logging functionality in ActiveRecord, and noticed that the SQL was being displayed only for every other record. After some grovelling around in the code, I realized that the problem was that every other line was being rendered in a font that happened to match the background font of my terminal window (lightish grey to white). If for no other reason than what I''ve just described, I think this fancy code in abstract_adapter.rb: def format_log_entry(message, dump = nil) if @@row_even then @@row_even = false; caller_color = "1;32"; message_color "4;33"; dump_color = "1;37" else @@row_even = true; caller_color = "1;36"; message_color "4;35"; dump_color = "0;37" end log_entry = " \e[#{message_color}m#{message}\e[m" log_entry << " \e[#{dump_color}m%s\e[m" % dump if dump.kind_of?(String) && !dump.nil? log_entry << " \e[#{dump_color}m%p\e[m" % dump if !dump.kind_of?(String) && !dump.nil? log_entry end should be jettisoned. I can give you two other reasons: 1) Most of my tools (less, xemacs, etc.) render this in a very ugly way (with the escape sequences intact). 2) If I really want colour, I can have a specialized logger. The advantage of being able to log the two parts of the message in different colours is marginal, at best--a specialized logger could still log every other line appropriately (heck, it could even pattern match for SQL statements, and restore the original functionality of white-on-white SQL logs :-). Even better, a post-processor for a simply formatted log can do all sorts of tricks. Why embed this stuff in the log itself? In any event, it was a (minor) waste of time figuring this out, so I''d like to suggest removing this code so that other people don''t go down the same path. Bob Sidebotham
>>>>> "Bob" == Bob Sidebotham <bob.sidebotham-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:[...] Bob> 1) Most of my tools (less, xemacs, etc.) render this in a Bob> very ugly way (with the escape sequences intact). less -r should display the sequences correctly. You can add export LESS="-r" To your shell''s startup file (adjusting for csh-ness accordingly) and it''ll do the right thing. Not that I don''t agree it''d be nice if the prettifying of the logs was configurable. -- Fletch | "If you find my answers frightening, __`''/| fletch at phydeaux.org| Vincent, you should cease askin'' \ o.O'' | scary questions." -- Jules =(___) | U
> Not that I don''t agree it''d be nice if the prettifying of the logs was > configurable.Me too. I just rejected a patch that flat out removed the colors, though. That obviously doesn''t work. The colors are there for a reason. But it would be nice if it was configurable. -- David Heinemeier Hansson, http://www.basecamphq.com/ -- Web-based Project Management http://www.rubyonrails.org/ -- Web-application framework for Ruby http://macromates.com/ -- TextMate: Code and markup editor (OS X) http://www.loudthinking.com/ -- Broadcasting Brain
On Tue, Nov 30, 2004 at 05:00:03PM +0100, David Heinemeier Hansson wrote:> >Not that I don''t agree it''d be nice if the prettifying of the logs was > >configurable. > > Me too. I just rejected a patch that flat out removed the colors, > though. That obviously doesn''t work. The colors are there for a reason. > But it would be nice if it was configurable.That''s OK, I won''t take it personally. However, I would like to clarify my position on the issue, so please allow me to retort. You say that the colors are there for a reason (but do not give one), but I can just as easily say that no other logs on any system I have access to are colored, and that there is a reason that they are not colored. Not every application or even every terminal can understand those color codes. You can make this configurable if you want to, it is your software afterall, but in keeping with "less software" and the "unix way", I really believe this type of thing belongs in an external tool. I might even go along with configurability, if coloring were consistent throughout Rails, but it''s not. The only coloring comes from AR''s SQL. Why aren''t Parameters colored? Or exceptions? Or the name of the controller? Or ... ? This is the path down which excessive configurability leads. A selling point of Rails has always seemed to be one of minimal configuration, and I think you should stick to that. Less software in Rails, specialized tools for specialized tasks. If someone wants "wowee neato" logs, it''s easy enough to pass it through some regex or even extend Log4r. There already exist tools to colorize logs based on a regex. The effectiveness of these tools I cannot say, because I do not use them (I do not want colored logs, afterall). I''ll also note that your reply to the email is not quite consistent with your note on the patch rejection. It either "obviously doesn''t work" or it does work if there is a "generic post-processing filter that gives the same effect and can be used with tail" written (not sure if you''re implying such a tool should be included with Rails or not there). Which is it? I am not sure in what tone I am supposed to take the former comment. At any rate, I''ve said enough about the subject. I stand firm in the belief that it is not the Right Way, but I''m sure we could argue about it all day long and not reach an agreement. That''s my two cents, take it or leave it. -Scott
On Tue, 30 Nov 2004 14:14:08 -0500, Scott Barron <scott-HDQKq3lYuGDk1uMJSBkQmQ@public.gmane.org> wrote:> That''s OK, I won''t take it personally.On the plus side (and since I brought this topic up with my slightly acerbic initial post, which I regretted the instant I posted it), I''ll have to note that if the biggest current public controversy in Rails is over colourization of logs, then things are looking rather rosy, indeed... I believe it''s called a "Tempest in a Teapot". I also think that David is astute enough to come round to the "Right Way", and see the light, eventually. I mean, the logs *are* pretty, so it must be hard to remove them :-). Peace, Bob
On Tue, Nov 30, 2004 at 12:03:58PM -0800, Bob Sidebotham wrote:> On Tue, 30 Nov 2004 14:14:08 -0500, Scott Barron <scott-HDQKq3lYuGDk1uMJSBkQmQ@public.gmane.org> wrote: > > > That''s OK, I won''t take it personally. > > On the plus side (and since I brought this topic up with my slightly > acerbic initial post, which I regretted the instant I posted it), I''ll > have to note that if the biggest current public controversy in Rails > is over colourization of logs, then things are looking rather rosy, > indeed... I believe it''s called a "Tempest in a Teapot".I think you''re spot on here. Come on, David, introduce some REAL problems for us to argue about ;)> I also think that David is astute enough to come round to the "Right > Way", and see the light, eventually. I mean, the logs *are* pretty, so > it must be hard to remove them :-).Indeed :) -Scott