log4mongo / log4mongo-python

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

TypeError: attribute name must be string, not 'int' #60

Open nabeenb opened 3 months ago

nabeenb commented 3 months ago

Python version = 3.11.8 pymongo = 4.5 2024-08-02T04:29:53.748307147Z File "/tmp/8dcb2a9152dfc2b/antenv/lib/python3.11/site-packages/log4mongo/handlers.py", line 244, in emit 2024-08-02T04:29:53.748310947Z if len(self.buffer) >= self.buffer_size or record.levelno >= getattr(logging, self.buffer_early_flush_level): 2024-08-02T04:29:53.748315147Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-08-02T04:29:53.748319347Z TypeError: attribute name must be string, not 'int'

Same code works on Python version 3.11.4 locally, but in Azure it's failing.

nabeenb commented 3 months ago

log4jmongo version = 1.8.1 Python version = 3.11.8 pymongo = 4.5 While logging to MongoDB via BufferedMongoHandler, get error all time TypeError: attribute name must be string, not 'int'

oz123 commented 3 months ago

Hi,

Can you try and figure more ? What are the message you are logging? Does it work with the non buffered handler?

adinovap20 commented 1 month ago

Hi,

I am also getting the same issue. My log4mongo version is also 1.8.1 and python version is 3.12.6.

The reason is that in handlers.py, there is a line in which a function getattr() is used.

if len(self.buffer) >= self.buffer_size or record.levelno >= getattr(logging, self.buffer_early_flush_level):
    self.flush_to_mongo()

This getattr function requires its second attribute to be a string.. Instead of this, we can change the code to this -

if len(self.buffer) >= self.buffer_size or record.levelno >= self.buffer_early_flush_level:
     self.flush_to_mongo()

@oz123 can you verify this once? I can create a PR for this then.