Takkun Takkun - 5 months ago 26
Python Question

Using the logging python class to write to a file?

How can I use the logging class in python to write to a file? Every time I try to use it, it just prints out the message.


An example using logging.basicConfig rather than logging.fileHandler()

                            format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',

logging.info("Running Urban Planning")

self.logger = logging.getLogger('urbanGUI')

In order, the five parts do the following: set the output file, set it to append rather than overwrite, determine the format of the output message, determine the format of the output time, and determine the minimum message level it will accept.