MARTIMM / raku-mongodb-driver

MongoDB driver for Raku
Artistic License 2.0
18 stars 8 forks source link

MongoDB::Logger doesn't play nice with Log::Async #29

Closed lefth closed 6 years ago

lefth commented 6 years ago

The following test code shows the problem. (I'm assuming a database "tvu" with collection "users". Change these to match the data that's in your DB.)

use MongoDB::Client;
use Log::Async;
my MongoDB::Client $client .= new(:uri("mongodb://127.0.0.1"));
my $db = $client.database('tvu');
logger.send-to($*OUT);
for $db.collection("users").find() -> $document {
    info ~$document;
}

The expected result is to see all the documents. The actual result is the following error, repeated many times:

No such method 'id' for invocant of type 'Any' in block at D:\rakudo\share\perl6\site\sources\1B022E7E13BEE5A72407C8392CD0C4153240767C (Log::Async) line 45 in block at D:\rakudo\share\perl6\site\sources\1B022E7E13BEE5A72407C8392CD0C4153240767C (Log::Async) line 49 in code at D:\rakudo\share\perl6\site\sources\9B568CCA1135076961258D53B50B2C064E633CAB line 175

Another reproducible error I see on Windows (not Linux, as far as I remember) is:

Use of uninitialized value of type Any in string context. Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful. in block at D:\rakudo\share\perl6\site\sources\9B568CCA1135076961258D53B50B2C064E633CAB (MongoDB::Log) line 34

lefth commented 6 years ago

I suggest if any plugin is going to change the logger or depend on its settings/instance not changing, it should create a private Log::Async instance instead of using the logger singleton.

Edit: That suggestion was surprisingly easy to implement. PR on the way...

MARTIMM commented 6 years ago

Thanks for the PR. I can learn a lot from you!