How to prevent logging warning?

Maksim Kasimov maksim.kasimov at gmail.com
Wed Oct 5 09:09:05 EDT 2005


may be this you will find usefull:

def getLog(logName, fileName = None):

     if fileName:
         hdl = logging.FileHandler(fileName)
     else:
         hdl = logging.StreamHandler()

     fmt = logging.Formatter("%(name)s:\t%(levelname)s:\t%(asctime)s:\t%(message)s")
     hdl.setFormatter(fmt)
     log = logging.getLogger(logName)
     log.addHandler(hdl)

     return log


Thomas Heller wrote:
> I'm about to add some logging calls to a library I have.  How can I
> prevent that the script that uses the library prints
> 'No handlers could be found for logger "comtypes.client"' when the
> script runs?
> 
> I would like to setup the logging so that there is no logging when
> nothing is configured, and no warning messages are printed.
> 
> Thomas


-- 
Best regards,
Maksim Kasimov
mailto: maksim.kasimov at gmail.com



More information about the Python-list mailing list