6 ms·
I couldn't find a logging library that worked for my library, so I made one
- malfist 11mo agoAlmost every logger in java operates this way. You set your library logging to debug and the end user and configure if they want debug logs from your library or not. They can even set context variables.
- throwaway150 11mo agoPython too. Honestly, any mature logger should allow embedding logs in library code that can be turned on or off by the end user. This was a solved problem 20 years ago. I honestly don't see what's so novel about this today. Or is this speaking to the sorry state of software engineering that plagues the JavaScript world?
- danudey 11mo agoRust also. Similar to this: OpenTelemetry has a golang library that allows you to instrument your library so that you can send traces, logs, etc. to an OTEL endpoint, but that instrumentation doesn't actually do anything unless the developer of the actual application uses a separate golang library to actually trigger, collect, and transmit those traces. Otherwise it's basically a no-op.
- bgoosman 11mo agoWasn't OpenTelemetry invented for this purpose?
- ramon156 11mo agoThe JS impl of OpenTel is awfully glued together. Sorry for the maintainers, but its inefficient and prometheus+logging will outmatch OT any day of the week (at least for JS)
- koakuma-chan 11mo agoWhich OpenTel impl isn't awfully glued together? When I looked at Rust implementation... I felt really bad. I feel like rolling my own logging is the only option.
- ramon156 11mo agoWell, touche. But then my conclusion would shift from "JS OT is bad" to "OT is bad". I'd hate that, because I like the idea about a standard for telemetry, but the reality is that most projects don't need this amount of insight (when you have to give up so much speed)
- cowlby 11mo agoThis feels a bit like a pub/sub pattern; I wonder what it would look like with a full pub/sub implementation.
- reactordev 11mo agoAt least you learned something
- drdec 11mo agoDid you consider log4js?
- seniorsassycat 11mo agoI really want something like this to be built into the language or runtime, I don't want to juggle configuration for 4 different libraries. Log4j and tracing seem to be well established without being built in, but it feels too late for js. I'm curious if this is enough https://nodejs.org/api/diagnostics_channel.html https://nodejs.org/api/diagnostics_channel.html I don't like the js hotel libraries, their docs feel deliberately obtuse
- KellyCriterion 11mo agoindustry-proven and mature libs like LOG4J or LOG4Net are not sufficient?
- hansvm 11mo agoYou mean this log4j [0] with major vulnerabilities the industry missed for nearly a decade? [0] https://en.wikipedia.org/wiki/Log4Shell https://en.wikipedia.org/wiki/Log4Shell
- mashepp 11mo agoSo you don’t use any software that has had a security vulnerability? What operating system and browser did you use to write your post?
- Veserv 11mo agoUnary thinking has no place when considering software quality or security. Just because things have vulnerabilities does not mean that the category, severity, and frequency of them is a irrelevant consideration. The Log4j vulnerability was effectively calling eval() on user input strings. That is utter incompetence to the extreme with immediately obvious, catastrophic consequences to anybody with any knowledge whatsoever of software security. That should be immediately disqualifying like a construction company delivering a house without a roof. "Oh yeah, anybody could forget to put a roof on a house. We can not hold them responsible for every little mistake." is nonsense. Basic, egregious errors are disqualifying. Now, it could be the case that everything is horribly defective and inadequate and everybody is grossly incompetent. That does not somehow magically make inadequacy adequate and appropriate for use. It is just that in software people get away with using systems unfit for purpose because they had "no choice but to use substandard components and harm their users so they could make money".
- KellyCriterion 11mo agoHave you used ever OpenSSL? :-D The thing is: A bug does not invalidate enterprise adoption - Microsoft ist a good example.
- callumgare 11mo ago[dead]
- monkpit 11mo agoThe OP is about LogTape…
- tengbretson 11mo agoLibraries shouldn't log. Just have your top-level abstractions extend an EventEmitter base, emit appropriate events, and let the user do the rest.
- ivan_gammel 11mo agoWhy shouldn’t libraries log?
- mrkeen 11mo agoBecause they have to be compatible with your logging implementation, and they were written first.
- charcircuit 11mo agoBecause libraries don't know where or even how the user wants it to log.
- Hackbraten 11mo agoThat's why a library (if it absolutely must do logging) should always allow the user to optionally inject their own logger implementation.
- throwway120385 11mo agoIt depends a lot on the language, but in my field libraries that have their own logging implementation and that don't provide hooks to override it cause big problems for me because I send all the logs to the same central logging client that forwards it to the same central logging server for aggregation. Your logging probably dumps it to a file, or it writes it to STDOUT, or something similar, in which case now I have to pipe all of that data in two places by doing something hacky. There are some language ecosystems that have good logging systems like Java which I would be totally fine with. But systems languages like C/C++ that don't have a core concept of a "log message" are a pain to deal with when the library author decides to stream some text message somewhere. Which is probably a good argument for not using those languages in some circles, but sometimes you have to use what you have. So it's not really a blanket "don't do it" but you should carefully consider whether there's some well-known mechanism for application authors to intake and manage your logging output, and if that doesn't exist you should provide some hooks or consider not logging at all except with some control.
- JSR_FDED 11mo agoSo many knee jerk comments from people who have not read the article. The author describes how existing logging systems are geared towards applications, and sometimes libraries need a way of logging that provides more granularity and control - especially when the library spans multiple levels of abstraction.