DEV Community

Discussion on: Logging REST API

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

I deployed my Docker container on Google Cloud Run. The rest is fully managed by Google.

GCR dashboard looks like this,

GCR dashboard

There seems to be no error message shown, even if the status is 500.

However, I am also asking about logging in development settings, e.g. localhost.

Collapse
 
ale_jacques profile image
Alexandre Jacques

On localhost, I usually don't log stuff, I debug. By that I mean using the debugger to view variable content, bodies, etc. inside my code. Eventually, I console.log() (or whatever your language console method is) things if I feel debugging is not necessary.

But that's MY workflow. If its for development stuff, I wouldn't worry much if I'm bloating my local server as I could easily delete logs.

Maybe I missunderstood what you're trying to do. :)

I don't know if you're already using but I'll leave here for reference for other people: Google Cloud Run has a logging feature: cloud.google.com/run/docs/logging.

Thread Thread
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

I use fastify which uses pino, which automatically log to console; but this can easily be a bad idea.

  • Too much text, and it will be trimmed.
  • Not using advantage of Chrome DevTools. Haven't tried --inspect flag yet.
  • Maybe logged history of a session inside a temporary database would be helpful?

Also, of course, I don't know how to make pino work well with GCR. As far as I read the guide, it still requires a decision of "what to log"?

Collapse
 
adrian110288 profile image
Adrian

When I develop in Node.js I log request/responses locally with debug and morgan/winston packages. They require little setup and work well for me.

Thread Thread
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

with debug

Can you explain more? I do realize the existence of Morgan and Winston, though.

There is also pino-debug, but I don't see it as helpful. Too much non-useful information.

Too much text, and it will be trimmed.

Have you tried, something like this. The error log size will destroy console output in VSCode. I believe it won't destroy chrome://inspect, though. (I edited the main post on how I made it work.)

await DbModel.insertMany(ARRAY_OF_HUNDREDS_OF_DUPLICATES, { ordered: false })