Python: 로그인 색상

2790 단어 pippythonlogcmd
로깅 모듈을 사용하는 경우 컬러 명령줄에 유용한 모듈을 사용해야 합니다.

https://pypi.org/project/coloredlogs/

설치:

pip install coloredlogs


정말 사용하기 쉽습니다.

import coloredlogs, logging

# Create a logger object.
logger = logging.getLogger(__name__)

# By default the install() function installs a handler on the root logger,
# this means that log messages from your code and log messages from the
# libraries that you use will all show up on the terminal.
coloredlogs.install(level='DEBUG')

# 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)

# 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")


그게 다야 ;-)

좋은 웹페이지 즐겨찾기