Skip to content

Redirect debug output from required modules? #505

Description

@AlCalzone

Hey 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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions