typegoose / mongodb-memory-server

Manage & spin up mongodb server binaries with zero(or slight) configuration for tests.
https://typegoose.github.io/mongodb-memory-server/
MIT License
2.56k stars 185 forks source link

Enabling debug mode through package.json does not work #834

Closed PiotrOwsiak closed 9 months ago

PiotrOwsiak commented 9 months ago

I'm using version 9.1.1 and enabling debugging log does not work through package.json. Enabling EXP_NET0LISTEN feature does work through package.json and enabling debugging through an environment variable does work. I did a quick check and it seems the problem is here:

// enable debug if "config.mongodbMemoryServer.debug" is true
if (envToBool(resolveConfig(ResolveConfigVariables.DEBUG)) && !debug.enabled('MongoMS:*')) {
  debug.enable('MongoMS:*');
  log('Debug Mode Enabled, through package.json');
}

in the condition the part debug.enabled('MongoMS:*') seems to be true, I have not investigated further but if I remove that part of the condition then enabling debugging log through package.json starts to work.

I had a quick look at the debug package docs and I believe you are using it slightly wrong, instead of

 debug.enable('MongoMS:*');

you should do:

 debug.enable('MongoMS');

and also check if it's enabled this way:

  debug.enabled('MongoMS');

cause

  debug.enable('MongoMS:*');

seems to always return true according to https://www.npmjs.com/package/debug#conventions: " If you append a "*" to the end of your name, it will always be enabled regardless of the setting of the DEBUG environment variable. "

hasezoey commented 9 months ago

please dont discard the issue template


otherwise i have confirmed that .enabled with a * in it will always return true, i didnt know that the conventions also applied there (i had thought there it would mean "any module with that prefix to be enabled").

this will be fixed in the next version

I had a quick look at the debug package docs and I believe you are using it slightly wrong, instead of

no, debug.enable('MongoMS'); will enable the module name exactly MongoMS not things like MongoMS:ResolveConfig

debug-js conventions

If you have more than one debuggers you should prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser".

debug-js wildcards

The * character may be used as a wildcard. Suppose for example your library has debuggers named "connect:bodyParser", "connect:compress", "connect:session", instead of listing all three with DEBUG=connect:bodyParser,connect:compress,connect:session, you may simply do DEBUG=connect:*, or to run everything using this module simply use DEBUG=*.

github-actions[bot] commented 9 months ago

:tada: This issue has been resolved in version 9.1.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

PiotrOwsiak commented 9 months ago

Sorry, I got scared by the big template, was in a hurry and thought it's a pretty simple bug report with an explanation already so it won't hurt if I discard the template to save some time.

Wow, you're right, I made a quick assumption that seemed logical to me, thanks for pointing that out :) I think the way * works is confusing and not intuitive, there is no symmetry there.

Anyway, kudos for super fast reaction and fix and thank you for the wonderful package, it's amazing IMHO and super useful.