Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging messages should not use string formatting #17

Open
rpdelaney opened this issue Jan 24, 2018 · 1 comment
Open

Logging messages should not use string formatting #17

rpdelaney opened this issue Jan 24, 2018 · 1 comment

Comments

@rpdelaney
Copy link
Collaborator

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 rpdelaney self-assigned this Jan 25, 2018
rpdelaney added a commit that referenced this issue Jun 7, 2018
This reverts commit 1f6b3b4.

This introduced a bug where console errors were printed:

--- 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 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,)
@rpdelaney
Copy link
Collaborator Author

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,)```

@rpdelaney rpdelaney reopened this Jun 7, 2018
@rpdelaney rpdelaney removed their assignment Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant