Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
关于 Python 日志记录格式的快速问题。
logging.basicConfig(filename='test.log', format='%(levelname)s %(message)s', level=logging.DEBUG)
这会给我记录消息,例如:
INFO Test
我现在想要的是在级别名称中添加括号,例如:
[INFO] Test
我应该如何修改格式参数?
这应该这样做。
logging.basicConfig(filename='test.log', format='[%(levelname)s] %(message)s', level=logging.DEBUG)