Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python logging format: how to add bracket

Tags:

python

logging

A quick question about Python logging format.

logging.basicConfig(filename='test.log', format='%(levelname)s %(message)s', level=logging.DEBUG)

This will give me logging messages like:

INFO Test

What I want now is to add bracket to the level name, like:

[INFO] Test

How should I modify the format argument?

like image 953
Cacheing Avatar asked Aug 06 '13 18:08

Cacheing


1 Answers

This should do it.

logging.basicConfig(filename='test.log', format='[%(levelname)s] %(message)s', level=logging.DEBUG)
like image 196
FastTurtle Avatar answered Oct 26 '22 03:10

FastTurtle