logging module

Bev in TX countryone77 at gmail.com
Sun Jul 1 19:32:59 EDT 2018



> On Jul 1, 2018, at 8:05 AM, Sharan Basappa <sharan.basappa at gmail.com> wrote:
> 
> Folks,
> 
> I am trying to use logging module and somehow I cannot make it work.

Saying that something does not work does not provide enough information for anyone to assist you.  You need to provide both the exact code that did not work, what you expected and what happened, and the error message that you received, if any.  Details, details and more details.

> 
> A simple code that I am trying is below. The commented code line 5,6 are other options I have tried but don't work
> 
> #importing module
> import logging
> 
> #Create and configure logger
> #logging.basicConfig(filename="D:/Projects/Initiatives/machine learning/programs/newfile.log",
> #logging.basicConfig(filename="newfile.log",
> logging.basicConfig(format='%(asctime)s %(message)s')
> 
> #Creating an object
> logger=logging.getLogger()
> 
> #Setting the threshold of logger to DEBUG
> logger.setLevel(logging.DEBUG)
> 
> #Test messages
> logger.debug("Harmless debug Message")
> logger.info("Just an information")
> logger.warning("Its a Warning")
> logger.error("Did you try to divide by zero")
> logger.critical("Internet is down")
> 
> PS: I am running this under Enthought Canopy
> 
> The following is the output
> %run "D:/Projects/Initiatives/machine learning/programs/debug_4.py"
> -- 
> https://mail.python.org/mailman/listinfo/python-list

Bev in TX







More information about the Python-list mailing list