Using logging module to log either to screen or a file

RedBaron dheeraj.gupta4 at gmail.com
Tue Dec 7 04:16:56 EST 2010


Hi,
I am beginner to python and i am writing a program that does a lot of
things. One of the requirements is that the program shud generate a
log file. I came across python loggging module and found it very
useful. But I have a few problems
Suppose by giving option '-v' along with the program the user can turn
off logging to a file and instead display log on the screen. Since I
am using a config file for logging, how do I accomplish this.
I tried to define two handlers (fil and screen) and added it to my
logger. But that logs data to both screen and the file. I need to log
it to only one. How do I dynamically remove one of the handler from
the logger based on user option. As a precursor how do i reference the
handlers defined in config file in the code??



More information about the Python-list mailing list