question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[RFC] Pluggable log handler

See original GitHub issue

Would you consider a PR that implemented support for globally defaulting log to something other than process.stderr? The way I’d expect this to work is debug would default to stderr unless process[Symbol.for(‘DEBUG_LOG’)] was set. Of course the local self.log would always take precedence.

The motivation for this feature is to allow an application to redirect all debug output to a logger of its choice, without knowing which all dependencies utilize debug.

I’ve chosen a global Symbol to circumvent the issue of multiple versions of debug in codebase.

Happy to submit this. Thoughts?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:6
  • Comments:22 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
Qix-commented, Jun 20, 2018

It might be much more practical to just have a top level function on the debug instance. However, it’s usually an anti-pattern to modify a package’s state in a way that affects other packages.

EventEmitters are a good candidate here, too.

const debug = require('debug');

debug.on('log', msg => writeToSomeStream(msg));
2reactions
Qix-commented, Sep 14, 2021

Doing a bit of poking around on this today, this appears to be soft-blocked by nodejs/node#40110. Not a deal-breaker but it’ll be less than advantageous without allowing users to do this with ESM modules.

The other issue is code-based linkage. If you add a handler via code instead of pre-loading modules, then we’ll run into the issue of libraries pre-loading their own handlers and causing unexpected output or mis-routed output (potentially) - something that, given the ubiquity of this package, simply won’t do.

There needs to be a way to either prevent or disable added log handlers in application code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RFC 3838 OPES Policy Requirements August 2004
Policy, Authorization, and Enforcement Requirements of the Open Pluggable Edge Services (OPES) (RFC 3838, August 2004)
Read more >
[RFC] Compatibility layer · Issue #644 · debug-js/debug · GitHub
I do like the idea of making debug more like SLF4J, where the user could write logging handlers and load them in using...
Read more >
RFC 7574: Peer-to-Peer Streaming Peer Protocol (PPSPP)
Let's call this protocol handler Peer A. Peer A parses the URL to ... As a result, every single chunk is acknowledged a...
Read more >
Pluggable Backend - ForgeRock Backstage
This is an abstract object type that cannot be instantiated. A Pluggable Backend stores application data in a pluggable database. Pluggable Backends. The ......
Read more >
Hudi - Confluence Mobile - Apache Software Foundation
RFCs are the way to propose large changes to Hudi and the RFC Process details how to go about ... RFC - 39...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found