Pyscript: name 'logger' is not defined

I have scripts running to activate lights, but I cannot seem to get the logging working. It seems the built-in variable ‘logger’ is not available. The ‘has’ variable is available though.

When I add a file with just on line to log a message to the pyscript folder I receive the error below.

Script:

logger.error('Test')

Error:

2023-01-26 00:08:19.615 ERROR (MainThread) [custom_components.pyscript.file.test_logger] Exception in </config/pyscript/test_logger.py> line 1:
    logger.error('Test')
    ^
NameError: name 'logger.error' is not defined

Does anyone have any idea how to troubleshoot this?

I am running:
Home Assistant 2023.1.7
Supervisor 2022.12.1
Operating System 9.4
Frontend 20230110.0 - latest
Pyscript 1.3.3

Does the documentation of this custom component say that logger should be available?

A quick look at the pyscript documentation shows slightly different logging examples that look like this: log.error(str).

Many thanks, I was really stuck on this issue.
log.error does work.
I was looking at the documentation for the integration ‘Python Scripts’ instead of ‘pyscript’, which wasn’t helpful of course.

1 Like