Saving systemd journal to disk from inside a snap

So I am working on a consumer facing product which means I have to deal with the fact that people will cycle power to the device when they see poor behavior. Which means that we lose logs containing information about that poor behavior.

We would like to flush the logs to disk on certain events but I can’t find any documentation as to how to accomplish this from inside a snap. Is this a feasible thing?


you can use the log-observe interface that gives you access to journalctl as well as read access to /var/log …

Hi, thanks for the quick response! We are using log-observe but that doesn’t seem to give me the ability to flush the log to disk that I’m looking for. Is there a specific call I’m missing?

ah, i misunderstood, i thought you wanted to capture them with or into your snap …

is this on an UbuntuCore device (on server and desktop installs rsyslog still runs in parallel) ?

Yes, this is an ubuntu core system. We have logging enabled and going to disk but we are seeing a fair amount of loss on power cycles that we’re trying to mitigate.

i quick hack for debugging might be to sequentially call journalctl --flush but that is indeed not a long term solution …

if your app comes from a brand store you could use a r/w system-files interface to dump configuration override snippets into /etc/systemd/journald.conf.d/

i’m sure there are ways to alter journald’s config to a point were it flushes more often.

Yeah, it’s a brand store application. I will try the system call approach but I was not able to call journalctl from inside the snap doing sudo snap run --shell which lead me to believe it was not an available function from inside one of the running applications.

well, was the log-observe interface connected at that time ? you should definitely be able to with it connected …