Add support to custom JSONEncoder
#656
Labels
api: logging
Issues related to the googleapis/python-logging API.
priority: p3
Desirable enhancement or fix. May not be included in next release.
type: feature request
‘Nice-to-have’ improvement, new feature or different behavior or design.
Is your feature request related to a problem? Please describe.
My company is moving out from structlog to start using this package, as it is intended to have better integration with google products. We're using
StructuredLogHandler
to send the log records to google cloud logging. But something structlog used to do out-of-the-box was the ability to automatically convert the extra data we provide to the logger to be sent to the stream, and therefore, we need to check all the calls we're making tologger.info()
,debug()
,warning()
, etc. to check if the data type is supported by JSONEncoder, otherwise the call tohadler.format()
will raiseTypeError
, stating thatObject of type PosixPath is not JSON serializable
(this is one example of error we're getting, because the default encoder cannot encodepathlib.Path
instances) and the log record will not be pushed to gcloud loggingDescribe the solution you'd like
I'd like to be able to specify a custom class to encode the message to JSON, so the formatting is handled by the encoder, not the caller of
logger.info()
and its siblingsDescribe alternatives you've considered
An alternative would be having a filter that prepares the data to be used by the handler, I'm even wrote a filter to handle that:
but it seems to me I'm deviating the purpose of log filters by doing that
Additional context
n/a for now
The text was updated successfully, but these errors were encountered: