log4mongo / log4mongo-python

python logging handler for mongo database
http://log4mongo.org
Other
111 stars 37 forks source link

Updated for compatibility with pymongo 4.0+ #52

Closed coca099 closed 1 year ago

coca099 commented 1 year ago

Tested on mongodb 6.0.1 and pymongo 4.3.3, should be compatible starting 5.0.0+ and 4.0 respectively. Tested on a DB with authentication enabled but it should work without too hopefully.

Quick disclaimer: I'm a total 0 with Python. Not going to lie, those are hot glued fixes until my debugger stopped turning red, I'm certain there's a better way to do things but at least it runs without crashing from my limited testing. Some of the methods and ways of doing things got changed when going from 4.0 to 5.0 like the way connections/clients are handled so I made some quick change to make it at least run. From what I understood, we shouldn't manage multiple connections from from one MongoClient anymore, methods like authenticate(), logout() and close() have been removed from the pymongo library, there's no connecting and disconnecting to do, authentication is done on the MongoClient object so I moved authentication there. Close() shouldn't be of any use now I think? I just None-d and false-d the relevant variables for now.

coca099 commented 1 year ago

I'm really sorry if I'm not doing things correctly, also sorry for the commit mess. I copy pasted the handler to my project and made changes until it ran, hopefully it's of use here.

oz123 commented 1 year ago

@coca099 thanks for your effort. Looks OK.

nyxgear commented 1 year ago

Hi, I find this update very useful and I was wondering if there are plans to make a new release of the module including it. Right now, version 1.7.0 does not include it.

Thank you