Override `log()` functions with global ones
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- javascript
- Domain
- tooling
Research direction
Start in src/common.js, reading setup(env) and the logging path around the existing self.log and createDebug.log selection. Compare the reported patch with the current behavior and verify that a user-defined global debug.log takes precedence over namespace-specific log functions while the default logger preserves existing behavior.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- JavaScript
- Stars
- 11.5k
- Forks
- 992
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from debug-js/debug
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Debug as JSON Open
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 28/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·