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

Silence logging #141

Open
luaVolk opened this issue Jan 7, 2019 · 10 comments
Open

Silence logging #141

luaVolk opened this issue Jan 7, 2019 · 10 comments

Comments

@luaVolk
Copy link

luaVolk commented Jan 7, 2019

It seems there's no way to stop mongo_dart from printing to the console. Or at least none that i can find.

I'm printing other things to the console but are buried with query logs.

Not sure if I'm missing something or not.

@luaVolk
Copy link
Author

luaVolk commented Jan 7, 2019

I should say i didnt have this problem back when i was using 0.3.2

@thosakwe
Copy link
Contributor

thosakwe commented Jan 7, 2019

Import package:logging, and set hierarchicalLoggingEnabled to true as early as possible in your application. This will solve your problem.

I wish this were true by default, but it's not, which is often quite annoying.

(EDIT: LMK if this doesn't solve it, BTW).

@thosakwe thosakwe closed this as completed Jan 7, 2019
@luaVolk
Copy link
Author

luaVolk commented Jan 7, 2019

Sorry but this made no difference

@thosakwe thosakwe reopened this Jan 7, 2019
@thosakwe
Copy link
Contributor

thosakwe commented Jan 7, 2019

Can you paste your output? Also, see if you can include the hierarchicalLoggingEnabled line as the very first line in your main().

@luaVolk
Copy link
Author

luaVolk commented Jan 7, 2019

For example everytime it makes queries

[FINE] {MongoMessageTransformer} - 2019-01-07 02:08:48.778124: MongoReplyMessage(ResponseTo:117, cursorId: 0, numberReturned:1, responseFlags:8, {...}})
[FINE] {Connection} - 2019-01-07 02:08:48.778190: MongoReplyMessage(ResponseTo:117, cursorId: 0, numberReturned:1, responseFlags:8, {...}})
[FINE] {Connection} - 2019-01-07 02:08:48.778231: Completing MongoReplyMessage(ResponseTo:117, cursorId: 0, numberReturned:1, responseFlags:8, {...}})
[FINE] {Connection} - 2019-01-07 02:08:48.778942: Execute MongoUpdateMessage(118, data.users, {...}})

(i replaced the contents of the queries with ... cause i cant share them)

and yes its the very first thing on the main function

@thosakwe
Copy link
Contributor

thosakwe commented Jan 7, 2019

Okay, so I can at least definitely see that these messages are from package:logging.

Try this:

hierarchicalLoggingEnabled = true;
Logger.root.level = Level.OFF;

@luaVolk
Copy link
Author

luaVolk commented Jan 7, 2019

The Logger.root.level = Level.OFF; alone worked.
Though this would be a problem if i wanted to use the logging package for something else

@thosakwe
Copy link
Contributor

thosakwe commented Jan 7, 2019

I don't think this is a problem with mongo_dart, actually. This package doesn't add any additional logic; it just creates instances of Logger.

Do you have an onRecord.listen(...) call anywhere? You don't want to call Logger.root.onRecord(...) if hierarchicalLoggingEnabled is true.

Instead, call it directly on your logger, i.e.:

hierarchicalLoggingEnabled = true;
Logger('my_logger').onRecord.listen(...);

@luaVolk
Copy link
Author

luaVolk commented Jan 7, 2019

I ended up not setting hierarchicalLoggingEnabled to true since it doesn't have to be for the root level.

I don't think this is a problem with mongo_dart, actually. This package doesn't add any additional logic; it just creates instances of Logger.

Usually in other packages there is a way to change the logging level of these Logger instances.

@thosakwe
Copy link
Contributor

thosakwe commented Jan 7, 2019

You can send a PR to make the loggers on MongoMessageHandler, etc. public.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants