appdaemon icon indicating copy to clipboard operation
appdaemon copied to clipboard

Logging (self.log) does not properly handle encoding of some non-English characters.

Open Aephir opened this issue 2 years ago • 1 comments

What happened?

The AppDaemon logger does not correctly log the non-English characters æ, ø, and å.

self.log("æøå")

logs:

2023-12-11 15:42:17.591901 INFO test: ������

There is a long version as well, as I found this when parsing data from an HTTP request. Here, I can see the a bit more of the character encoding, etc., but I'm not sure if that part is necessary. If so, find it by expanding the details below.

Logging a retrieved http request (with requests and json imported):

response = requests.get(url, headers=headers)
self.log(response.text)

logs the response, with characters that elsewhere are displayed correctly as ø here shown as \u00f8.

If I use json.loads:

response = requests.get(url, headers=headers)
product_info = json.loads(response.text)
self.log(product_info)

It displays the ø as ��. But it looks like it's only a logging issue, as:

response = requests.get(url, headers=headers)
product_info = json.loads(response.text)
weird_encoding = product_info['location']['name']  # access the string with an 'ø'
self.log(weird_encoding)
self.log("ø" in weird_encoding)

logs:

2023-12-11 15:25:11.935265 INFO test: K��kkenskab
2023-12-11 15:25:11.935895 INFO test: True

Version

4.4.2

Installation type

Home Assistant add-on

Relevant log output

The addon does not log the version of AppDaemon, only the version of HA, HA-OS and the Addon.

For AppDaemon it simply shows using AppDaemon 4.x.

Logs:

-----------------------------------------------------------
 Add-on: AppDaemon
 Python Apps and Dashboard using AppDaemon 4.x for Home Assistant
-----------------------------------------------------------
 Add-on version: 0.16.0
 You are running the latest version of this add-on.
 System: Home Assistant OS 11.2  (amd64 / qemux86-64)
 Home Assistant Core: 2023.12.1
 Home Assistant Supervisor: 2023.11.6
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.

From the addon github repo (https://github.com/hassio-addons/addon-appdaemon/tree/main/appdaemon) I'd guess it's AppDaemon v4.4.2.

Relevant code in the app or config file that caused the issue

No response

Anything else?

No response

Aephir avatar Dec 11 '23 14:12 Aephir

I have this bug too. AppDaemon v4.4.2 in Python 3.11 virtual environment. I have checked that sys.stdout.encoding is UTF-8, app is written using VS Code in UTF-8. Same code prints correctly if I run it in python.

It can be solved with optional argument ascii_encode for log which is True by default and for UTF-8 it should be False: self.log("æøå", ascii_encode=False)

andreid1303 avatar Jan 19 '24 16:01 andreid1303