1

I'd like to make the line numbers of the logger statement colored. As far as I've found out, I have to write a complete new code for that [1]. Is there any shorter way to make lines of following logger colored? i.e change the %(lineno)d' part so Terminal would have colors in line numbers. Thanks.

logging.basicConfig(level=logging.DEBUG,
       format='%(name)-12s %(funcName)s() %(message)s %(lineno)d')  
logger = logging.getLogger(__name__)

[1] Python Colorlog not printing in the log files with colors

2
  • 4
    I think you should look again at the answer to the question you refer to. It explains how the colours are achieved and why it is a bad idea to put the required non-printing characters into logfiles. You would to do better to write a simple Python program that reads the logfile and colorizes the line numbers as they are sent to the terminal. Commented Jan 5, 2019 at 18:27
  • What the previous comment states (it may be OK to use for screen output, but would not put color information in a log file). But also coloring output depends on your terminal. Esp. difference between native windows and U*X system with ANSI control codes support is rather substantial. You can have a look for instance at colorama. Commented Jan 6, 2019 at 0:23

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.