3 Gm^i @sJddlmZddlZddlZddZGdddejZdedfdd ZdS) )print_functionNcCst|S)z$Formatter for unserialisable values.)str)objr7/tmp/pip-build-6pq8b46l/crhelper/crhelper/log_helper.py_json_formattersrcs(eZdZdZfddZddZZS) JsonFormatterzAWS Lambda Logging formatter. Formats the log message as a JSON encoded string. If the message is a dict it will be used directly. If the message can be parsed as JSON, then the parse d value is used in the output record. c s:tt|jdddd|_|jj||jdt|_dS)Nz %(asctime)sz %(levelname)sz %(name)s.%(funcName)s:%(lineno)d) timestamplevellocationZ json_default)superr__init__ format_dictupdatepoprdefault_json_formatter)selfkwargs) __class__rrr s  zJsonFormatter.__init__c s|jj|j|d<fdd|jjD}tdtrLd|d<n<|j|d<ytj |d|d<Wnt t fk rYnX|j r|j s|j|j |_ |j r|j |d<tj||jd}t|dr|jd }|S) Nasctimecsi|]\}}|r||qSrr).0kv) record_dictrr "sz(JsonFormatter.format..msgmessage exception)defaultdecodezutf-8)__dict__copy formatTimeritems isinstancedict getMessagejsonloads TypeError ValueErrorexc_infoexc_textformatExceptiondumpsrhasattrr)rrecordZlog_dictZ json_recordr)rrformats(      zJsonFormatter.format)__name__ __module__ __qualname____doc__r r1 __classcell__rr)rrr s rDEBUGcKs~|r&x tjjD]}|j|f|qWtjj||s:|}tjdj|tjdj|tjdj|tjdj|dS)NZbotoZboto3Zbotocoreurllib3)loggingroothandlers setFormattersetLevel getLogger)r Z formatter_clsZ boto_levelrhandlerrrrsetupFs r@) __future__rr'r9r Formatterrr@rrrrs ;