0

I have a webapp (Flask) and I need to enable some logging. I need to log to a mysql table with the columns:

id, timestamp, userid, orderid, service, msg, response

I would like to use the python's std logging. Example usage would be:

special_logger = logging.getSpecialLogger() # instead of logging.getLogger()

special_logger.setLevel(level=logging.DEBUG)
special_logger.addHandler(myMysqlHandler)
special_logger.debug(current_uid, myorderid, 'SERVICE1', 'Exception happened', serviceResponse)

How I can achieve that?

1
  • I updated my answer in response to your comment. Commented Sep 16, 2014 at 16:42

1 Answer 1

1

Just use a normal logger, and a database handler as described in this answer. Although my other answer doesn't address MySQL specifically, it uses DB-API and so should be adaptable to a MySQL Python driver which conforms to DB-API 2.0.

Update: You can pass extra data to the log by following the documentation here.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the answer. I can write an LogHandler. The problem is that I need to pass extra data in the logger. Check the last line in the code in the question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.