DEV Community

Tony Pujals
Tony Pujals

Posted on • Updated on

Cloud Run - basic logging for your TypeScript app

In the previous article, you deployed your TypeScript app to Cloud Run.

Cloud Run will capture basic logs based on what you print to stdout and stderr, generally what you write using console.log and console.error.

After deploying the app, you can use a new gcloud command that's currently in beta to read or even tail your logs.

First, ensure you've got beta support:

gcloud components install beta
Enter fullscreen mode Exit fullscreen mode

Or, if you already had it installed, but just want to update:

gcloud components update
Enter fullscreen mode Exit fullscreen mode

Now you can read your logs:

gcloud beta run services logs read [SERVICE] \
  --project=[PROJECT] \
  --region=[REGION] \
  --limit=10
Enter fullscreen mode Exit fullscreen mode

You should see something like this:

log output

You can also tail your logs:

gcloud beta run services logs tail blogdemo --project javascript-demos
Enter fullscreen mode Exit fullscreen mode

And, of course, now every time you send a request, you'll see a log entry print to your terminal, similar to this:

Image description

For the project that you generated in the previous article, update the logs and logs:tail scripts in package.json with the values you used for deploy:

  • [SERVICE] - the name of your service
  • [PROJECT] - your cloud project ID
  • [REGION] - the region you deployed to

Then you can run either npm logs or npm logs:tail.

Next

In the next article, you'll see how you can get more value out of your logs using structured logging, which among other things, will help you correlate logs by HTTP request.

Top comments (0)