Skip to content

Fix TypeError in logging call #47

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

Merged
merged 3 commits into from
Jan 27, 2023
Merged

Conversation

aphedges
Copy link
Contributor

@aphedges aphedges commented Jan 27, 2023

Without the %d present in the log message string, the call to logger.info() as always throwing a TypeError upon running the server.

I created a short script, logging_bug.py for testing:

import logging
from scienceworld import ScienceWorldEnv
logging.basicConfig(level=logging.INFO)
ScienceWorldEnv()

Here is the output before and after my fix:

$ python logging_bug.py
INFO:py4j.java_gateway:Callback Server Starting
INFO:py4j.java_gateway:Socket listening on ('127.0.0.1', 62918)
--- Logging error ---
Traceback (most recent call last):
  File "/Users/ahedges/.pyenv/versions/3.8.15/lib/python3.8/logging/__init__.py", line 1085, in emit
    msg = self.format(record)
  File "/Users/ahedges/.pyenv/versions/3.8.15/lib/python3.8/logging/__init__.py", line 929, in format
    return fmt.format(record)
  File "/Users/ahedges/.pyenv/versions/3.8.15/lib/python3.8/logging/__init__.py", line 668, in format
    record.message = record.getMessage()
  File "/Users/ahedges/.pyenv/versions/3.8.15/lib/python3.8/logging/__init__.py", line 373, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "logging_bug.py", line 4, in <module>
    ScienceWorldEnv()
  File "/Users/ahedges/projects/personal/ScienceWorld/scienceworld/scienceworld.py", line 51, in __init__
    logger.info("ScienceWorld server running on port", port)
Message: 'ScienceWorld server running on port'
Arguments: (62917,)
$ python logging_bug.py
INFO:py4j.java_gateway:Callback Server Starting
INFO:py4j.java_gateway:Socket listening on ('127.0.0.1', 62936)
INFO:scienceworld.scienceworld:ScienceWorld server running on port 62935

I also made two other small changes while I was at it.

Without the `%d` present in the log message string, the call to
`logger.info()` as always throwing a `TypeError` upon running the
server.
@MarcCote MarcCote merged commit 7851d72 into allenai:main Jan 27, 2023
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

Successfully merging this pull request may close these issues.

2 participants