I use python module logging
to generate log files and console print.
I set up my script to log all errors levels, without DEBUG to file.
But i have trouble with set up handler for console printing. On console i want to display level INFO
and below, not up like setLevel
doing. Is any way to do this with inline code?
Asked
Active
Viewed 1,067 times
0

Galmi
- 743
- 1
- 11
- 18
-
http://stackoverflow.com/questions/1383254/logging-streamhandler-and-standard-streams might be help full. – Roman Bodnarchuk May 21 '11 at 08:05
1 Answers
4
I'm not sure exactly what you mean by "inline code", but you can achieve this using Filters.
class InfoAndLower(logging.Filter):
def filter(self, record):
return record.levelno <= logging.INFO
and then attach a filter instance to your console handler.
h = logging.StreamHandler(sys.stdout)
h.addFilter(InfoAndLower())
In Python 3.2 and later, you don't need to create a class - a callable will do:
h.addFilter(lambda record: record.levelno <= logging.INFO)

Vinay Sajip
- 95,872
- 14
- 179
- 191