clasp
clasp copied to clipboard
clasp run should have an option to print logs
Expected Behavior
Just like executing a command in a shell sends output to the terminal, clasp run
should have an option to do so as well.
Actual Behavior
Need to start a clasp logs --watch
or monitor stackdriver logs separately.
+1 to this request. I've managed to create a somewhat satisfactory workaround using a shell script:
#!/bin/bash
set -e
trap "exit" INT TERM ERR
trap "kill 0" EXIT
clasp logs --watch --json | grep '"message": "not ok' &
clasp run $1
sleep ${2:-20}
(The grep piece may need changing to suit your own requirements)
FWIW, this might not be feasible to do as part of the run command.
The two main issues are:
- logging is asynchronous to the script execution
- The script process ID isn't returned from scripts.run, so there's no way to correlate log entries to an execution.
The end result is there's no reliable way to know if all the logs have been written nor filter them to the specific execution. All the command can do is just wait for an arbitrary period of time then stop and hope it got everything. The logs can be noisy as well if running a function for a deployed script being used elsewhere.
Given those restrictions, I'm inclined to say the above workaround of tailing the logs in the background or in another tab is acceptable and it's unlikely built-in support will offer a better experience.
Out of curiosity, if clasp logs is meant to expose just the logs, is there one to see output generated from console.log() calls within the apps script?