Closed dchaley closed 3 days ago
yes, we have seen this in other envs too - would be interested to hear what the Batch team says about this...
From Shamel:
Use this library: https://pypi.org/project/JSON-log-formatter/
Then do something like this:
import logging
from json_log_formatter import JSONFormatter
class GCPFormatter(JSONFormatter):
def json_record(self, message: str, extra: dict, record: logging.LogRecord) -> dict:
extra['severity'] = record.levelname
return super(GCPFormatter, self).json_record(message, extra, record)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
formatter = GCPFormatter()
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.info("Log message", extra={'custom_field_1': "foo", 'custom_field_2': "bar"})
Some of the logs show up as errors even though they're labeled info or debug. This is disconcerting 😅 figure out why...