rpdelaney-archive / python-chess-annotator

Reads chess games in PGN format and adds annotations using an engine
GNU General Public License v3.0
62 stars 29 forks source link

Logging messages should not use string formatting #17

Open rpdelaney opened 6 years ago

rpdelaney commented 6 years ago

Very minor issue but I need to note this down so I don't forget to correct it later. I've just learned that while string formatting is recommended in many (most?) contexts, it is not a good idea in logging messages. Some explanation is here. The relevant pylint messages are:

  Line: 440
    pylint: logging-format-interpolation / Use % formatting in logging functions and pass the % parameters as arguments (col 20)
  Line: 443
    pylint: logging-format-interpolation / Use % formatting in logging functions and pass the % parameters as arguments (col 16)
  Line: 599
    pylint: logging-format-interpolation / Use % formatting in logging functions and pass the % parameters as arguments (col 17)
  Line: 748
    pylint: logging-format-interpolation / Use % formatting in logging functions and pass the % parameters as arguments (col 36)
rpdelaney commented 6 years ago

1f6b3b4 introduced a logger warning and so I reverted it in 6a6ae60.


Traceback (most recent call last):
  File "/usr/lib/python3.6/logging/__init__.py", line 992, in emit
    msg = self.format(record)
  File "/usr/lib/python3.6/logging/__init__.py", line 838, in format
    return fmt.format(record)
  File "/usr/lib/python3.6/logging/__init__.py", line 575, in format
    record.message = record.getMessage()
  File "/usr/lib/python3.6/logging/__init__.py", line 338, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "annotator/__main__.py", line 759, in <module>
    main()
  File "annotator/__main__.py", line 743, in main
    analyzed_game = analyze_game(game, args.gametime, args.engine, args.threads)
  File "annotator/__main__.py", line 590, in analyze_game
    game, root_node, ply_count = classify_opening(game)
  File "annotator/__main__.py", line 443, in classify_opening
    logger.info("Classifying the opening for non-variant ", variant, "game ...")
Message: 'Classifying the opening for non-variant '
Arguments: ('chess', 'game ...')
--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.6/logging/__init__.py", line 992, in emit
    msg = self.format(record)
  File "/usr/lib/python3.6/logging/__init__.py", line 838, in format
    return fmt.format(record)
  File "/usr/lib/python3.6/logging/__init__.py", line 575, in format
    record.message = record.getMessage()
  File "/usr/lib/python3.6/logging/__init__.py", line 338, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "annotator/__main__.py", line 759, in <module>
    main()
  File "annotator/__main__.py", line 743, in main
    analyzed_game = analyze_game(game, args.gametime, args.engine, args.threads)
  File "annotator/__main__.py", line 599, in analyze_game
    logger.debug("Total budget is {} seconds", budget)
Message: 'Total budget is {} seconds'
Arguments: (60.0,)```