JSON loggers & tapping promises?

Happy new year! :tada:

2 questions:

  1. what json logger y’all recommend?
  2. how do I tap in the new promise lib?

JSON Logger

What are y’all using for JSON loggers, or logging libraries in general? I only use ReScript on the server, typically in AWS Lambda which means a JSON logger is preferable. In my Node.js days, I’d use something like pino or Bunyan/Winston on inherited projects that were probably Express.js/Restify in server/EC2 environments.

At the end of the day, all those logs were printed to standard out, which then goes to CloudWatch, which then somehow goes to ElasticCache/ELK/Splunk. As long as you print JSON out in your console.log, you’re good.

I’ve built a 3 line adapter + ReScript binding in the past to horribly-named-but-wonderfully-pretty debug module. While pretty and helpful to debug manual integration tests locally, that wouldn’t fly for qa and production. I reckon I can use pino again with a simple adapter, just was curious if y’all could recommend one, ReScript or JavaScript. I’m currently using Jzon, so I’m ok with writing encoders using it to ensure the log that is turned into JSON is actually legit.

Tapping in New Promise Lib

On the tail of above, I use Promises all over the place since I’m a Railway Programming Aficionado. I’m using the new ReScript Promise lib and I’m curious how to make a tap function; is that even possible in ReScript? Probably not “because types”, but I’m a n00b so maybe? :crossed_fingers:t3:

Here’s what I’d do in JS:

const tap = label => (...args) => {
	console.log(label, args)
        // pino.log(label, safeArgs(args))
	return Promise.resolve.apply(Promise, args)

Then using it in practice:

const verifyToken = (fetch, verifyJWSFunc, event) =>
  .then( tap("headers extracted from event, getting auth header...") )
  .then( getAuthHeaderMaybe )
  .then( tap("auth header obtained, parsing...") )
  .then( parseAuthHeader )
  .then( tap("header parsed, verifying...") )

‘Tap’ seems pretty easy:

let tap = (label, arg) => {
  Js.log2(label, arg)

Should work like:


Since tap("label") should return a function that takes only a single argument.

1 Like

Rad, I just tested your code with mine and it works, appreciate it!

1 Like

For the logger, I just wrapped LambdaLogger with a horrible API of my own.

1 Like