Blitz: Add helpful and pretty logging for RPC calls

Created on 14 Apr 2020  Â·  10Comments  Â·  Source: blitz-js/blitz

  • We want to log RPC events to give Blitz developers insight into the system and for troubleshooting.
  • Logs should be helpful. I.e. only log helpful things and no more
  • Logs should be beautiful
  • Logs should use color unless NODE_ENV = 'production'

Things I think we should log at a minimum:

  • [ ] Query/mutation name
  • [ ] Timestamp
  • [ ] Duration
  • [ ] Input parameters
  • [ ] Output, whether successful query/mutation output or a thrown error

For reference, here's the current output logged from packages/core/src/rpc.ts:

[query:getProducts] HEAD ""
[query:getProducts] SUCCESS 200
[query:getProducts] POST {"params":null}
[query:getProducts] SUCCESS [{"id":1,"handle":"shorts","name":"Shorts","description":"very nice","price":45}]
[query:getProducts] POST {"params":null}
[query:getProducts] SUCCESS [{"id":1,"handle":"shorts","name":"Shorts","description":"very nice","price":45}]
[query:getProducts] POST {"params":null}
[query:getProducts] SUCCESS [{"id":1,"handle":"shorts","name":"Shorts","description":"very nice","price":45}]
[query:getProducts] POST {"params":null}
[query:getProducts] SUCCESS [{"id":1,"handle":"shorts","name":"Shorts","description":"very nice","price":45}]
scopcore statuready-to-work-on

Most helpful comment

@flybayer @tsawan Will look into third party logging solutions when I do the cli stuff.

All 10 comments

I read logging code in rpc.ts eariler. No plan to use a logging library like winston https://github.com/winstonjs/winston?

@tsawan Good point, I think we should use a logging library. I don't have opinion on which one.

Using a logging library is related to @merelinguist's work on pretty logging

just checked and winston has very good support for colors (linked with log-levels).
@merelinguist can you please check if it will fit our needs?

@flybayer @tsawan Will look into third party logging solutions when I do the cli stuff.

Hey @merelinguist, could you provide a brief update on if you've started on more CLI logging stuff and when you think you might start/finish?

@flybayer Working on this. I want to create some docs about how we should do logging, so expect a pr for that soon (tomorrow I hope).

Whoever wants to work on this should refer to this new logging file:

https://github.com/blitz-js/blitz/blob/456d3e88d5b7ddc7a03970d16883e999fda1d1dc/packages/server/src/log.ts

@merelinguist this would be amazing to have for the alpha if you're up for doing it? — I know you'd make it look incredible :)

@flybayer Sorry I didn’t see this! I can probably get it done by 6pm gmt?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

flybayer picture flybayer  Â·  3Comments

markhaehnel picture markhaehnel  Â·  3Comments

SharadKumar picture SharadKumar  Â·  3Comments

flybayer picture flybayer  Â·  4Comments

netheril96 picture netheril96  Â·  4Comments