Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • Where is YELLOW, WHITE, BLUE, etc. defined? Commented May 22, 2009 at 16:20
  • 2
    @Swaroop - Those are ANSI escape codes, which you can read look up on Google, or find here: en.wikipedia.org/wiki/ANSI_escape_code, or alternatively pueblo.sourceforge.net/doc/manual/ansi_color_codes.html Commented Aug 16, 2009 at 20:56
  • 67
    I don't believe that you should create a logger subclass just for this - your answer is fine as far as creating a specialised Formatter and specifying its use on a StreamHandler. But there's no need for a logger subclass. In fact the use of a logger class adds a handler to every logger created, which is not what you typically want. Commented Aug 17, 2009 at 12:17
  • 4
    @simon: plumberjack.blogspot.co.uk/2010/12/… Commented Mar 22, 2012 at 23:08
  • 9
    One side note to ColoredFormatter. It's changing the record object, which is passed further to other handlers or propagated to other loggers. If you have configured file loggers etc. you probably don't want to have the colors in the log files. To avoid that, it's probably best, to simply create a copy of record with copy.copy() before manipulating the levelname attribute, or to reset the levelname to the previous value, before returning the formatted string. Commented Apr 20, 2013 at 13:31