2

When trying to get a logger object from the Python logging module:

logging.basicConfig()
logger = logging.getlogger("logger")
logger.setLevel(logging.DEBUG)
logger.propagate = True

I encountered the following error:

Traceback (most recent call last):
  File "tools/train_net_step.py", line 22, in <module>
    import utils.net as net_utils
  File ~/lib/utils/net.py", line 12, in <module>
    logger = logging.getlogger(__name__)
AttributeError: 'module' object has no attribute 'getlogger'
2
  • Your code is using the same spelling as the one in the solution, so one of the two has to be wrong, no? Commented Jan 25, 2020 at 19:17
  • @AMC yes, thank you for catching that. I updated the question accordingly. Commented Jan 25, 2020 at 21:06

2 Answers 2

3

In my case my script unfortunately had the name logging.py
The statement using logging then did not use the library I wanted but my script instead.
After renaming it to logging_test.py the error message disappeared.

Sign up to request clarification or add additional context in comments.

1 Comment

I had a similar problem. I was getting conflicts because of a script called token.py in my project.
3

Function names are case-sensitive.

logging.getlogger()
# or
logging.GetLogger()

is different than

logging.getLogger() # here getLogger is the correct function name

Using the correct, case sensitive function call successfully initialized the logger object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.