openid / AppAuth-JS

JavaScript client SDK for communicating with OAuth 2.0 and OpenID Connect providers.
Apache License 2.0
977 stars 162 forks source link

Can logging be disabled? #75

Open pofallon opened 6 years ago

pofallon commented 6 years ago

Expected Behavior

Ideally it would not log steps to the console by default, or logging could be disabled. I see the IS_LOG value in the "flags" module, but it's defined as a const and I'm not sure how I can affect that value at run time in a way to prevent logging. Thanks!

Describe the problem

Actual Behavior

Currently the library prints messages to the console as it's executing, such as: Checking to see if there is an authorization response to be delivered. (here)

Steps to reproduce the behavior

Invoking the library functions as demonstrated in the Electron sample application

Environment

tikurahul commented 6 years ago

I will add some documentation on how this can be done.

someone1 commented 5 years ago

I remember asking this a while back as well - the code can't be optimized away (due to the const IS_LOG value) with default build configs such as with webpack4.

Even in a production build where the logging may be discarded, the code is still in the optimized bundles since it can't be detected as unused/dead code by UglifyJS2. I think when I asked before you mentioned there was a way with the "Closure compiler" but I'm still not clear on that.

Other optimization questions (sorry, I don't mean to hijack this issue) - is this package sideEffect free? Can we add the setting to the package.json? Will the target build be able to be tree shaken properly and such (doesn't the tsc compiler target ES3 by default)? I like the idea of hybrid deployments with ES2015+ as described in this article - it's a little beyond me so excuse me if this project is already setup for it but it would be nice to see this package updated as such.

tikurahul commented 5 years ago

My apologies. I lost track of this. I am going to document this. Stay tuned.

uifox commented 5 years ago

Hey @tikurahul Any update on how logging could be disabled? Thanks.

tikurahul commented 5 years ago

I have not started on this one yet. TBH. Will try a few things with closure compiler flags. As @someone1 said the const on the flag is probably going to be problematic, and I am going to fix it to make it a configurable value at build time.

someone1 commented 5 years ago

Whatever method is used, can you ensure it also works for those of us using Webpack + UglifyJS?

tikurahul commented 5 years ago

Yes. Will make sure I try that as well.

ArthurKnoep commented 4 years ago

Are there any updates on this ?

KevinDanikowski commented 4 years ago

Bump

aikoven commented 4 years ago

For now one can manually edit node_modules/@openid/appauth/built/flags.js file to set IS_LOG = false and then use patch-package to persist these changes.

relu91 commented 2 months ago

If you don't care too much about bundle optimization (e.g., you are working on Node cli application), the correct way (with the current codebase) to disable logging should be:

const { setFlag } = require('@openid/appauth/built/flags')
// ...
setFlag('IS_LOG', false);

@tikurahul let me know if I missed something.