Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override log() functions with global ones #886

Open
piranna opened this issue Apr 19, 2022 · 3 comments
Open

Override log() functions with global ones #886

piranna opened this issue Apr 19, 2022 · 3 comments

Comments

@piranna
Copy link

piranna commented Apr 19, 2022

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.

@shryao1

This comment was marked as spam.

@HoraceYH

This comment was marked as spam.

@Enanamy

This comment was marked as spam.

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

No branches or pull requests

4 participants