log4mongo / log4mongo-python

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

how to log connection error #57

Open nabeenb opened 11 months ago

nabeenb commented 11 months ago

I am unable to log into a log file for any connection error, while it prints to stdout

--- Logging error --- Traceback (most recent call last): lib/python3.11/site-packages/log4mongo/handlers.py", line 295, in flush_to_mongo getattr(self.collection, write_many_method)(self.buffer)

Please let me know if anyone has already solved this.

oz123 commented 11 months ago

Please share more code, this is impossible to help you like this.

nabeenb commented 11 months ago

try: mongo = BufferedMongoHandler(host=uri,

username='',

                          #password='',
                          database_name='chatlogs',
                          collection='logs',
                          authentication_db='chatlogs',
                          capped=True,
                          buffer_size=1000,                           # buffer size.
                          buffer_periodical_flush_timing=60.0,       # periodical flush every 60 seconds
                          buffer_early_flush_level=logging.CRITICAL)

log = logging.getLogger(name) log.addHandler(mongo) except Exception as e: logger.error (f"Could not connect to mongodb server: {traceback.format_exc()}", e.traceback ) raise CustomAPIException(e._message, e.code)

nabeenb commented 11 months ago

just to add my requirement is to log the connection error to a separate file instead standard output