Mohamed Mohamed - 3 years ago 109
Python Question

what I've done to get ValueError in logging module python

I want to write log to both file and stdout, Hence I use this code but I always get this ValueError in stdout but not in file.

I want logging from INFO level and above to get to both stdout and a file. and DEBUG level and above to be wrote to a file.

import logging

format='%(asctime)s %(name)-12s %(levelname)-8s %(funcName)-5s %(message)s',

console = logging.StreamHandler()
formatter = logging.Formatter('%(levelname):-8s %(message)s')

dic = {'Google Drive': '', 'Mega': '//', 'Openload': '', 'Streamango': '', 'Cloudy': '', '': '', 'Mp4upload': ''}'The dic: {}'.format(dic))


--- Logging error ---
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/", line 992, in emit
msg = self.format(record)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/", line 838, in format
return fmt.format(record)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/", line 578, in format
s = self.formatMessage(record)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/", line 547, in formatMessage
return self._style.format(record)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/", line 391, in format
return self._fmt % record.__dict__
ValueError: unsupported format character ':' (0x3a) at index 12
Call stack:
File "/Users/hamza/Dropbox/My Py Projects/Okanime/testing", line 18, in <module>'The dic: {}'.format(dic))
Message: "The dic: {'Google Drive': '', 'Mega': '//', 'Openload': '', 'Streamango': '', 'Cloudy': '', '': '', 'Mp4upload': ''}"
Arguments: ()

Answer Source
formatter = logging.Formatter('%(levelname)-8s : %(message)s')

This syntax fix the error in the Formatter

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download