Configure hook stdout (log)

Where do configure hook stdout (log) msgs go?

For reference, this is handled here.

If the hook completes successfully, the output goes nowhere. However, if it fails, the output is shown. How it’s shown depends on how the hook was run. If via snap set, it’ll be shown to the user. If via an update or install, I believe it’ll be in the change.

The usual way to debug during development is to add various echo statements to stdout and / or stderr.
Having to add exit 1 at the end of the configure script just to see my output seems wrong.

Is there a way to view stdout and stderr statements from the configure hook by setting an environment variable?

1 Like

An env variable (like VERBOSE, DEV_MODE) that enables the display of everything, and the preservation of SNAP_DATA in case of failure (it currently disappears) would probably make sense.

To work around the problem, I use the following pattern which probably should be documented somewhere as a best practice. Snap developers will want to see stdout and stderr during development, regardless of whether the hook script has completed successfully or not.

# in hook script
hook_dir="${SNAP_COMMON}/hooks/${SNAP_REVISION}/$(basename "$0")" && mkdir -p "${hook_dir}"

exec &> >(tee -a "${hook_dir}.log")

I also added some of the dump helpers I use in this post: