I am trying to print a variable using logging.debug and running into below error,how to fix it?
logging.debug('ATTEMPTS:{0}',attempts)
Error:-
Traceback (most recent call last):
File "C:\Python27\lib\logging\__init__.py", line 846, in emit
msg = self.format(record)
File "C:\Python27\lib\logging\__init__.py", line 723, in format
return fmt.format(record)
File "C:\Python27\lib\logging\__init__.py", line 464, in format
record.message = record.getMessage()
File "C:\Python27\lib\logging\__init__.py", line 328, in getMessage
msg = msg % self.args
TypeError: not all arguments converted during string formatting
You could either use
logging.debug('ATTEMPTS:%s', attempts)
or
logging.debug('ATTEMPTS:{0}'.format(attempts))
The first method passes two parameters into the logging.debug function which will automatically format the log. The second method passes in a single pre-formatted string into the logging.debug function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With