Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

logging.debug error during string formatting

Tags:

python

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

1 Answers

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.

like image 72
victorlin Avatar answered Jul 27 '26 06:07

victorlin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!