-
Notifications
You must be signed in to change notification settings - Fork 327
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved logger #557
Improved logger #557
Conversation
- info, debug and error loggers - different color for each of them - ability to customize debug of other ipfs packages via `localStorage.debug`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left a few comments for things you might want to check/change but otherwise it LGTM.
@@ -97,6 +97,7 @@ | |||
}, | |||
"dependencies": { | |||
"choo": "6.13.0", | |||
"debug": "https://github.com/visionmedia/debug/tarball/207a6a2d53507ec9dd57c94c46cc7d3dd272306d/debug.tar.gz", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non version number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, fix for webextension context (debug-js/debug#476) was not released yet.
// LOG | ||
// production: localStorage.debug = 'ipfs-companion:*,-*:debug' | ||
// dev: localStorage.debug = 'ipfs-companion:*' | ||
localStorage.debug = 'ipfs-companion:*,-*:debug' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this come from the manifest? Or some sort of user config/env var?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, in my libdweb branch I had to do this to enable logging: https://github.com/ipfs-shipyard/ipfs-companion/pull/553/files#diff-fc43b78eb6e482a2ad1a6924959d9ec1R4
Does this definitely work in Chrome?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙄 I'm really bad at reading the PR description...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this come from the manifest? Or some sort of user config/env var?
I hoped we could override it via web-ext run
's --pref
(or via env: $WEB_EXT_PREF
) but this parameter works only for browser's settings from about:config
.
WebExtension's Preferences are now kept in separate storage thet can't be overridden on the fly without additional code.
As a workaround, I was thinking about Preferences screen in extension itself: adding a simple checkbox (that adds or removes -*:debug
) or an input which enables you to edit localStorage.debug
(and enable logs from js-ipfs, libp2p etc). Personally I'd go with input, as it gives more control to developers and power users who want to look under the hood. As long we keep it in Experiments section it should be fine.
@alanshaw what do you think? does it feel useful?
|
||
module.exports = (loggerName) => { | ||
const log = debug(`${root}:${loggerName}`) | ||
log.debug = debug(`${log.namespace}:debug`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO log
and log.error
are enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, if we just drop log.debug
and use log
everywhere,
should we set the default to:
- hide non-errors by via something like
localStorage.debug = '*:error'
- or print all Companion logs
localStorage.debug = 'ipfs-companion:*'
?
I guess if we add an option to customize log filter on Preferences we could hide by default.
Update: debug v4.x works correctly in webextension context! |
This PR tries to address the problem of noisy console logs in tests and a chore of adding debug ones during development.
console.log
to debugdebug
library vialocalStorage.debug
Known Issues / Open Questions
debug
v3.1.0 does not work correctly in webextension context.It was fixed in Drop usage of
chrome.storage
(or make the storage backend pluggable) debug-js/debug#476 but not released yet, so this PR uses specific git revision instead of npm release.This is just an initial stab to see how it could work.
cc @alanshaw, @olizilla Do we have already established logging conventions in other JS projects that should be applied here? Personal opinions are also useful :)