debug icon indicating copy to clipboard operation
debug copied to clipboard

Override `log()` functions with global ones

Open piranna opened this issue 3 years ago • 3 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] 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.

piranna avatar Apr 19 '22 18:04 piranna

This is interesting

shryao1 avatar Apr 27 '22 19:04 shryao1

That's great

HoraceYH avatar Apr 30 '22 10:04 HoraceYH

Great

Enanamy avatar May 01 '22 17:05 Enanamy