Closed neilpanchal closed 1 year ago
Hello @neilpanchal. What do you think of an approach like https://github.com/stripe/stripe-python/pull/913 ?
If we made that change, then you would have access to the underlying params used to construct the log message when defining your own formatter, so there should be no need to monkey-patch/modify "logfmt" in util.
For example:
class MyFormatter(logging.Formatter):
def format(self, record):
# record.args won't be populated today, but would be if #913 were merged
return json.dumps(record.args)
logging.basicConfig()
formatter = MyFormatter('')
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger = logging.getLogger('stripe')
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
Anybody else feel free to chime in, too! We're happy to merge https://github.com/stripe/stripe-python/pull/913 and we think this solves the use case here, but we want to validate it against a user just to be sure!
@liveFreeOrCode (great handle, btw) I noticed you gave the issue a thumb. Would you be willing to take a glance at https://github.com/stripe/stripe-python/pull/913 to see if it would solve your problem?
@richardm-stripe This would work well, thanks for taking the time to address. We've since removed logging stripe records, so I am not able to test things but from what I can see, LGMT and seems reasonable.
Released in v5.1.0
Hello,
It would be great to allow users to format logs in json format instead of the hardcoded
logfmt
format in the library. For those looking to make this work, this is how we did it:Reference this class from
stripe_log_formatter.py
in log ini configuration file as follows:And then at import time, monkey patch stripe library:
Any chance we can get an ability to configure our own log formatter?