Tags: multani/structlog-gcp
Tags
Fix error reporting formatting (#98) The stacktrace for an error was formatted as: ${message} ${stacktrace} I'm pretty sure I saw that documented in Google Cloud's documentation when I initially implemented this feature, but I can't find it anymore and the current documentation from https://cloud.google.com/error-reporting/docs/formatting-error-messages#log-error now says: > To log an error event that is a stack trace, write the error event as > one of these types: > [...] > > * A `jsonPayload` that includes a `message`, `stack_trace`, or > `exception` field. > > You can specify more than one of those fields. If more than one of > those fields is specified, then the order of evaluation is: `stack_trace`, > then `exception`, and then `message`. > > If the `message` field is evaluated and if it isn't empty, then the > stack trace is captured only when the field contains a stack trace in > one of the supported programming language formats. The stack trace isn't > captured by Error Reporting when an unsupported format is used. > > If your error event is formatted as a `ReportedErrorEvent` object, > then copy its fields to the `jsonPayload`. For more information and an > example, see Log an error that is formatted as a ReportedErrorEvent > object. There's no mention of this weird `${message}\n${stacktrace}` anymore, so let's get rid of it.
Allow to override the log level while logging exceptions (#79) While logging information during an exception `except` block, instead of overwriting the log level with `CRITICAL`, the log level used by the caller will be set instead. This allows the caller to use: ```python try: raise ValueError() except Exception as exc: logger.info(f"I was expecting this error: {exc}") ``` The log message will be logged as `INFO` level, whereas it was logged as `CRITICAL` before. If an `exception` attribute is still passed to the logger, as in `logger.info("something", exception=exc)`, the log level will be `INFO` as expected but the error will also still be correctly reported (in Error Reporting + the bubble in Cloud Logging)
PreviousNext