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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved logger #557

Closed
wants to merge 1 commit into from
Closed

Improved logger #557

wants to merge 1 commit into from

Conversation

lidel
Copy link
Member

@lidel lidel commented Aug 26, 2018

This PR tries to address the problem of noisy console logs in tests and a chore of adding debug ones during development.

  • switched from console.log to debug
  • light convention of default, debug and error loggers
  • hardcoded different color for each logger type
  • ability to customize debug level of other ipfs packages using debug library via localStorage.debug
    • can be changed here but we could expose this on the Preferences screen (either as input or checkbox to enable debug logger) to help users and developers in troubleshooting

Known Issues / Open Questions

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 :)

- info, debug and error loggers
- different color for each of them
- ability to customize debug of other ipfs packages
  via `localStorage.debug`
@lidel lidel added the kind/maintenance Work required to avoid breaking changes or harm to project's status quo label Aug 26, 2018
@lidel lidel requested review from olizilla and alanshaw August 26, 2018 19:55
Copy link
Member

@alanshaw alanshaw left a 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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non version number?

Copy link
Member Author

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'
Copy link
Member

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?

Copy link
Member

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?

Copy link
Member

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...

Copy link
Member Author

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`)
Copy link
Member

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.

Copy link
Member Author

@lidel lidel Aug 28, 2018

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.

@lidel
Copy link
Member Author

lidel commented Apr 16, 2019

Update: debug v4.x works correctly in webextension context!
Closing this PR as it got superseded by #712

@lidel lidel closed this Apr 16, 2019
@lidel lidel deleted the improved-logger branch April 16, 2019 21:36
@ghost ghost removed the status/in-progress In progress label Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/maintenance Work required to avoid breaking changes or harm to project's status quo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants