8000 Override `log()` functions with global ones · Issue #886 · debug-js/debug · GitHub
[go: up one dir, main page]

Skip to content
Override log() functions with global ones #886
Open
@piranna

Description

@piranna

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch debug@4.3.4 for the project I'm working on.

As stated in #873, docs says that if setting a global debug.log() function, it will override the ones later specified at namespaces. This patch checks that debug.log() is different from the default one, and if so, then it has been defined by the user and will use it unconditionally.

Here is the diff that solved my problem:

diff --git a/node_modules/debug/src/common.js b/node_modules/debug/src/common.js
index e3291b2..e90e700 100644
--- a/node_modules/debug/src/common.js
+++ b/node_modules/debug/src/common.js
@@ -5,6 +5,8 @@
  */
 
 function setup(env) {
+	const globalLog = env.log;
+
 	createDebug.debug = createDebug;
 	createDebug.default = createDebug;
 	createDebug.coerce = coerce;
@@ -109,7 +111,9 @@ function setup(env) {
 			// Apply env-specific formatting (colors, etc.)
 			createDebug.formatArgs.call(self, args);
 
-			const logFn = self.log || createDebug.log;
+			const logFn = globalLog !== createDebug.log
+				? createDebug.log
+				: (self.log || createDebug.log);
 			logFn.apply(self, args);
 		}
 

This issue body was partially generated by patch-package.

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

      0