Redirect debug output from required modules?
See original GitHub issueHey all, I have a NodeJS-application in which I’m trying to redirect the debug output from modules I require. Not sure if I’m doing something wrong or what I want is not possible, so I thought I’d ask.
My situation is as follows:
App => has a custom debug log I want to redirect the logs to
|-- Module A => logs debug messages with debug("namespace-a")(message...)
|-- Module B => logs debug messages with debug("namespace-b")(message...)
In the app, I am using the following code to replace the log function of the sub modules with my custom one:
process.env.DEBUG = "*";
const debugPackage = require("debug");
const debuggers = [debugPackage("namespace-a"), debugPackage("namespace-b")];
for (const d of debuggers) {
d.log = (str) => customLogFunction(str);
}
However I’m not getting any redirected logs. Am I missing something?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Redirect debug output from required modules? #505 - GitHub
Hey all, I have a NodeJS-application in which I'm trying to redirect the debug output from modules I require.
Read more >How to redirect output of one module only to a file?
In a module you want to redirect everything to stdout. import sys stdout_sav = sys.stdout fout = open('file.log', 'w') sys.stdout = fout ...
Read more >Redirect output of debug command to copy.content module
Hello community,I want to Redirect output of debug command to copy.content module, to gather hosts facts and copy it locally inside a file ......
Read more >Redirect debug output of bash script to file - blog of stigok
I needed a way to debug my thunar (file manager) custom actions, as it doesn't have a way of debugging these scripts itself....
Read more >Capture all the logs - Gleb Bahmutov
Perfect - can we capture the log calls to the debug instances? Well, debug module writes directly into process.stderr stream bypassing console.* ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The problem is that when you do
debugPackage("namespace-a")
it creates a new debug instance every time, so it’s not going to affect another “namespace-a” instance that is in a different file.Instead, you can overwrite the
debugPackage.log
function in the same way, which will affect all created debug instances.npm ls debug
gives:The first three (until dtls-client) are the ones I’m interested in. It should probably work then, since they are all @3.1.0. Or can the outdated version from tar-pack screw me here?