Log to both stdout/err and logfile in hass.io?

i’m running hass.io with appdeamon and wondering if there is a way to have appdeamon log to stdout/err as well as a log file so I can still use the hassio/addon log UI to see the log ?

Hello,

Yes its possible, and the way is you could set the log in appdaemon.yaml to stdout/err, so you can use the hassio/addon log UI to see the log.

Then have an app set to priority 1, within it you use the self.listen_log() feature to listen to all log entries , and have it written into a file like log.log.

Regards

you know that the listen_log wasnt perfect when 3.0.2 was released, dont you? :wink:

@maxandersen stdout/err is also a logfile.
your system logfiles.
the log UI is just a program that shows the last few loglines from system that are about appdaemon.

listen_log as mentioned by odianosen is available to the latest appdaemon addon, but there will be a few small changes in the next release because it wasnt perfect at that time. so be aware of that when you try it.

Yeah should have remembered that :smirk:

i’m on hass.io so how do i tail the loglines from what log UI shows ?

afaics log UI shows the output of appdemon since when I change the logfile setting in appdaemon.yaml then log ui stops showing anything.

i have no clue about hassio, so i cant tell you how to tail logs there. (i dont know anything about tailing either :wink: )

what were you expecting in the log?
it shows only your errors and logging you put in apps.
so if you have no errors and dont use logging in apps, the log shows only that what is generated at startup

i use the logging to actually figure out what is going on when I write the apps - I haven’t found any other way to test/verify things in appdaemon.

makes sense.
i got a dashboard that shows my logs.

but i dont know why your log doesnt show anything. are you sure AD is still running?

I can see logs just fine but only in either log files or stdout. Wanted to see it in both.

I reckon I’ll have to do it by listening to the log as suggested as a workaround.

but like i said, the logs are there in system logs.
or else the hassio addon couldnt read them.
unless hassio would send it directly to the screen, which would mean you never would have history.

I don’t grok why you think it reads from a log file - it just shows stdout/err of the appdeamon. And yes lack of history is why I would like the log files.

because when you are on any other kind of system (then hassio) when log is set to stdout it goes to the system logfiles.
so i dont think the addon changes that.
i think the addon just does it like normal AD and when you look at the logscreen its just a tail from the systemlog.

Never seen that happen. When you run appdeamon stand-alone the same thing happens. Stdout/stderr goes to the console and if you put file name for the log file it stops showing up in the console.

Anyhow - listening to the log programmatically seems to be the solution.

if you run appdaemon from the commandline and you have stdout it will not go to a log but to the terminalscreen.

it says so also in the docs:

  • logfile (optional) is the path to where you want AppDaemon to keep its main log. When run from the command line this is not used -log messages come out on the terminal. When running as a daemon this is where the log information will go. In the example above I created a directory specifically for AppDaemon to run from, although there is no reason you can’t keep it in the appdaemon directory of the cloned repository. If logfile = STDOUT , output will be sent to stdout instead of stderr when running in the foreground, if not specified, output will be sent to STDOUT.

if appdaemon is run as daemon, the output still goes to a log even when STDOUT is selected.
and i am pretty sure that hassio runs appdaemon as daemon.

so all you need to do is tail the systemlog and still get the output.

but off course you can also create your own log app.

yes, in the very specific situation when you run appdeamon as a system deamon then content goes to system log - that is not what happens when running in cli nor in hass.io.

And if that was the case I would still like to find a way to have a log file dedicated to only appdeamon content which you don’t need root/admin permissions to access.

Anyways, time to find a utility to dump to a file which will rotate/truncate files automatically.

thats actually not a specific situation. its the most used situation. (the daemon startup is used for everyone that uses AD to startup on device startup, with a service or manual with -d)
its that or a manual startup in a terminal screen.
and i am 99,99% sure that hassio starts AD with the -d option.

but like you said, you want a dedicated log.
you probably want something like python logger with the listen_log function.
if you got a working app, i am interested too.
i tried it with logger, but i couldnt get it to work like expected fast enough, so i let it be for the time being.