var/opt/nydus/ops/primordial/log/__pycache__/envelope.cpython-38.pyc000064400000012551147206050410021504 0ustar00U af@sddlZddlZddlZddlmZddlmZddlZddlmZddl m Z ddl m Z ddl mZmZmZmZmZeeZGdd d e ejd ZGd d d eZdS) N)datetime)Optional) iso8601_utc)LogExtra)LogData)EnvelopeVersion EnvelopeRole ConfigLogData HostLogDataPayloadLogDatac@s8eZdZdZdZdZedeje e e ddddZ dS) EnvelopezCustomized envelope for sending log data. Given a log record, envelope version and configuration data, constructs a log message in the required format which can be returned as a json. Zenvelope_versionZ data_schemaN)record configLogDataenvelopeVersionreturnc Cst|tji}d}t|tr`ztjf|}Wn2tk r^}ztdt |W5d}~XYnXt|t st }t|tr| t j dk r| t j }t |}| t j}|dkrt||||Stdt |t ||t S)aA factory method for producing an Envelope instance. :param record: The log record :param configLogData: The logging data :param envelopeVersion: The version of the envelope :returns: A new Envelope object :rtype: :class:`Envelope` N&Unable to process extra log fields: %szszEnvelopeV1.loadConfigcCs t|j|_||j|jdS)z%Load the payload from the log record.N)r r r8r7 PAYLOAD_FIELDrGr$r$r%rAs zEnvelopeV1.loadPayloadcCs||jt|jdS)zLoad the host data.N)r7 HOST_FIELDr r rGr$r$r%r@szEnvelopeV1.loadHostcCs:tt|jjtj}||j|||j |jj dS)z)Load relevant fields from the log record.N) rr fromtimestampr createdpytzutcr7TIMESTAMP_FIELDSEVERITY_FIELD levelname)r:r2r$r$r%r?szEnvelopeV1.loadRecordFieldsc Cst|jtrz|jtjD]z\}}||jkr6q"||jkr||jkrt|t rv|D]\}}|j ||q\qt dq| ||q"|j ||q"Wn2t k r}ztdt|W5d}~XYnXdS)zLoad any "extra" data.zPayload is not of type 'dict'rN)rr rrritemsEXTRA_IGNORE_FIELDSEXTRA_MODIFIABLE_FIELDSrLrr8r7 ValueErrorrrrr)r:kvkeyvalr!r$r$r%rBs      zEnvelopeV1.loadExtra)'r&r'r(r)rCrHrIr rrMrLrDrrErFrSrJrRrKZROLE_DEVELOPMENTZ DEFAULT_ROLEZFIELDSrWr*rVr,r-rr rr6r9r=r>rAr@r?rB __classcell__r$r$r;r%rCsd   r)abcr,logging.configrtypingrrPZprimordial.timeutilsrZprimordial.log.extrarZprimordial.log.datarZprimordial.log.envelopedatarrr r r getLoggerr&rABCMetar rr$r$r$r%s      .