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

how to log connection error #57

Open
nabeenb opened this issue Dec 18, 2023 · 3 comments
Open

how to log connection error #57

nabeenb opened this issue Dec 18, 2023 · 3 comments

Comments

@nabeenb
Copy link

nabeenb commented Dec 18, 2023

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
Copy link
Collaborator

oz123 commented Dec 18, 2023

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

@nabeenb
Copy link
Author

nabeenb commented Dec 18, 2023

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
Copy link
Author

nabeenb commented Dec 18, 2023

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

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