launchdarkly / python-server-sdk

LaunchDarkly Server-side SDK for Python
https://docs.launchdarkly.com/sdk/server-side/python
Other
38 stars 45 forks source link

Override the logging when "Error posting diagnostic event" occurs #208

Closed mkeithsp closed 1 year ago

mkeithsp commented 1 year ago

Is your feature request related to a problem? Please describe. We have build a logging library that is designed to output messages in a particular format, and we have built alerts/dashboards based on that format. When launchdarkly encounters errors posting diagnostic events, it outputs a basic message to std out, which our alerts/dashboards interpret as a critical error even though it is not. I'm not aware of how I can override or customize the behavior of these logs.

Describe the solution you'd like An ability to pass in custom logging infrastructure to the launch darkly client or config. For example, it could be an object called logger that has a method called log that takes message as an argument. The custom logger object passed in is then able to log the message as it sees fit, and in our case we would simply embed the message into our standard logging format and it would play nicely with our alerting / dashboards.

Describe alternatives you've considered An ability to disable the native logging. Re-implement the 'EventProcessor' class in order to customize it, but there is a bit more nuance there and while it may be possible to do so, it seems a rather expensive / time-consuming solution.

Additional context Add any other context about the feature request here.

keelerm84 commented 1 year ago

Good morning and my apologies for the delay in getting back to you.

Python allows you to grab an instance of a named logger and register a new handler (and associated formatter) with it. Would this be a viable solution?

import logging

formatter = logging.Formatter(fmt="{ \"message\": \"%(message)s\" }")
handler = logging.StreamHandler()
handler.setFormatter(formatter)

log = logging.getLogger('ldclient.util')
log.addHandler(handler)

# With formatter: { "message": "Example log message." }
# Without formatter: Example log message.

NOTE: ldclient.util is the name of the logger used by most of the SDK. However, there is another logger ldclient.flag which we can also sometimes use for historic reasons. So you would want to register your handler to both of those.

github-actions[bot] commented 1 year ago

This issue is marked as stale because it has been open for 30 days without activity. Remove the stale label or comment, or this will be closed in 7 days.