sherif-fanous/Pyecobee

Logger

joshuarlowry opened this issue · 6 comments

When working with your example code I get some issues that "logger is not defined". I'm not sure If I'm missing something.

I need a little bit more information to try to help you.

Can you post details about your environment (Python version) and the code?

I'm trying to use it in google colab.

Python Version: '3.6.9 (default, Apr 18 2020, 01:56:04) \n[GCC 8.4.0]'

https://colab.research.google.com/drive/1r4157SorJ_jCuv-xI06bDZgu8LVIaQSj?usp=sharing

NameError                                 Traceback (most recent call last)
<ipython-input-2-6abbbef959ed> in <module>()
     64 
     65     if ecobee_service.authorization_token is None:
---> 66         authorize(ecobee_service)
     67 
     68     if ecobee_service.access_token is None:

<ipython-input-2-6abbbef959ed> in authorize(ecobee_service)
     37 def authorize(ecobee_service):
     38     authorize_response = ecobee_service.authorize()
---> 39     logger.debug('AutorizeResponse returned from ecobee_service.authorize():\n{0}'.format(
     40         authorize_response.pretty_format()))
     41 

NameError: name 'logger' is not defined

Add the following code after your imports

logger = logging.getLogger(__name__)

Please let me know if it fixes your issue and I'll fix the documentation accordingly.

Thanks

That fixed the logger message. Thank you.

Now I need to figure out why it doesn't show me the log messages in colab.

Also needed:

logging.basicConfig(
    level=logging.DEBUG # allow DEBUG level messages to pass through the logger
    )

The above no longer serves to print the messages in colab (3.7.13 (default, Apr 24 2022, 01:04:09)
[GCC 7.5.0]).

However, you can print or just call the statements in a cell and the result will display in the notebook.

Examples:

print(authorize_response.pretty_format())
print('Authorization Token => {0}'.format(ecobee_service.authorization_token))

or

authorize_response.pretty_format()
'Authorization Token => {0}'.format(ecobee_service.authorization_token