I couldn't find a logging library that worked for my library, so I made one

15 points by hongminhee


snej

I started using LogTape a few months ago and really like it.

The only serious complaint I have is there’s no way to check whether a particular log call would have any effect, so I can’t skip a potentially-expensive debug-level log call when there’s no debug logging enabled. By potentially-expensive I mean one where it’s expensive to compute the args that will be logged, like calling Array.map to extract a list of keys from a bunch of database records.

I’m also sad that implicit contexts aren’t implemented in web browsers, so I can’t take advantage of that. (It's a TC39 stage 2 proposal that node/deno/bun have already adopted but browsers haven’t, and Firefox has taken a negative position on it for some reason, which doesn’t bode well.)

repl

Isn't this how every Java and Python logging library works? I'm surprised something like this didn't exist in JS.

thangalin

Of possible interest:

https://dave.autonoma.ca/blog/2022/01/08/logging-code-smell/

Swapping logging libraries is a great example of why duplicating logging statements throughout the code base can be improved upon by using an event-based architecture, which allows isolating the log statement to a single line of code.