quantum231
quantum231

Reputation: 2591

How to make whole line same color in coloredlogs output in Python

I have just started using the coloredlogs package in Python. I am using the version 15.0. I can see that my message changes color depending on its log level (info, debug, warning e.t.c.). However, the other parts of the message remain the same color as shown below:

enter image description here

The code I used for this is below:

import coloredlogs, logging

# Create a logger object.
logger = logging.getLogger("main")

# If you don't want to see log messages from libraries, you can pass a
# specific logger object to the install() function. In this case only log
# messages originating from that logger will show up on the terminal.
coloredlogs.install(level='DEBUG', logger=logger, fmt='%(name)s - %(levelname)s - %(message)s')

# Some examples.
logger.debug("this is a debugging message")
logger.info("this is an informational message")
logger.warning("this is a warning message")
logger.error("this is an error message")
logger.critical("this is a critical message")

Upvotes: 4

Views: 268

Answers (1)

user7660047
user7660047

Reputation: 166

Try logger = logging.getLogger(__name__)

Upvotes: 1

Related Questions