To be clear, I already understand that I can view the logs through the frontend by clicking on the addon of interest. However, I would like to tail the logs in a separate log viewing program to make it easier to filter and view human-readable timestamps for the purposes of debugging.
The log I am interested in right now is the embedded mosquito broker. Considering that I am using hassio, is it possible for me to access that log file via SSH or SAMBA?
I am working on a few plugins and thinking of setting up logging of the applications that run in the containers to output to a /share/logs/appx folder.
Maybe also work on a separate that would manage these logs (rotate/prune/archive/consolidate) and provide a web based viewer.
This seems like more of a framework capability that hassio should provide.
Looking at my containers, it looks like add-ons use journald logging. You can use journalctl to view them from the host, but you can also just use docker logs.
As far as I can tell, they’re not saved to a file anywhere. You could potentially write an add-on that has access to the host docker (see the Portainer add-on for an example) and use that to dump the logs to a file somewhere.
There are some files under /var/log/journal but I’m on my phone and can’t check them right now.
I would assume so if it’s running HassOS but I’m not 100% sure. For journalctl, you need access to the host.
I have it running on Proxmox so I’m not sure if it’s the same on the Pi, but I get a terminal on the device (probably just plug in a keyboard and monitor to the Pi?), username is root to get to the Hassio command line, then type login and it will drop you into a terminal on the host.
However, for docker logs you can probably do it through the community SSH add-on by disabling protection mode, which gives it access to the host Docker.
Based on docker inspect ..., add-ons are using the host’s journald.
But there is no journalctl in the ssh add-on.
So you have to ssh into the host, and there you can use sg. like journalctl CONTAINER_NAME=addon_... Use sg. like docker ps to see the add-on’s container names.
This way you can see into the past and you can see the logs of stopped add-ons also. Cool.
As of supervisor version 2022.10.2 the /api/host/logs endpoint allows clients to interface directly with the system journal via supervisor. You can make calls to this endpoint from the cli by doing ha host logs. It doesn’t have all the options of journalctl but it has enough to cover this use case. To see logs for a particular addon you can do this:
ha host logs --identifier addon_core_mosquitto
Replace core_mosquitto with the slug of the addon you want to see logs for. The only kind of gotcha is that you have to prefix the addon slug with addon_ since it has to be the docker container name.
You can also limit the results to a specific number of rows, specific boot of the machine and tail with the other options:
> ha host logs -h
Allows you to look at the systemd journal on the host to see logs
across services and boots.
Usage:
ha host logs [flags]
ha host logs [command]
Aliases:
logs, log, lg
Examples:
ha host logs
Available Commands:
boots Show all boot IDs by offset
identifiers Show all syslog identifiers
Flags:
-b, --boot string Logs of particular boot ID
-f, --follow Continuously print new log entries
-h, --help help for logs
-t, --identifier string Show entries with the specified syslog identifier
-n, --lines int32 Number of log entries to show
This can all be done from the ssh or vscode addons without going directly to the host shell.