Is it possible to print to the console from a snap hook without including exit 1
? I want to print few warning messages from configure
hook.
no, it is not, but you can use logger -t $SNAP "$MESSAGE"
from inside your hook to write to the journal though …
Hello I followed your method and included the logger
command in configure
hook. During installation of my snap, the configure
hook get executed. My service has install-mode
disabled. I am running the following journalctl
command in host system.
sudo journalctl -r -u snap.<snapname>.<servicename>
But I can’t see any warning messages getting printed after installation.
ah, sorry, it should have been logger -t $SNAP_NAME ...
here is an example where i make pretty excessive use of it in the install hook:
I have fixed the command logger -t ${SNAP_NAME} "warning"
but when I run the following journalctl
command in host system it doesn’t show the message.
sudo journalctl -r -u snap.<snapname>.<servicename>
I can only find the service logs.
it will just log under the snap name, not necessarily under the service name …
you could indeed craft the -t option in a way it uses something like snap.${SNAP_NAME}.<servicename>
as tag though, but not sure if journald considers it part of the service then …
Found the logs by passing the tag flag while running journalctl
.
sudo journalctl -r -t $SNAP_NAME