clasp icon indicating copy to clipboard operation
clasp copied to clipboard

clasp run should have an option to print logs

Open vsekhar opened this issue 5 years ago • 3 comments

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.

vsekhar avatar Jan 10 '20 20:01 vsekhar

+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)

dwl285 avatar Mar 31 '21 12:03 dwl285

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.

sqrrrl avatar Jun 02 '21 17:06 sqrrrl

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?

caquinovs avatar Jul 21 '21 13:07 caquinovs