deeppavlov/core/agent/dialog_logger.py
def _log(self, utterance: Any, direction: str, dialog_id: Optional[Hashable]=None):
        """Logs single dialog utterance to current dialog log file.

        Args:
            utterance: Dialog utterance.
            direction: 'in' or 'out' utterance direction.
            dialog_id: Dialog ID.
        """
        if isinstance(utterance, str):
            pass
        elif isinstance(utterance, RichMessage):
            utterance = utterance.json()
        elif isinstance(utterance, (list, dict)):
            utterance = jsonify_data(utterance)
        else:
            utterance = str(utterance)

        dialog_id = str(dialog_id) if not isinstance(dialog_id, str) else dialog_id

        if self.log_file.tell() >= self.log_max_size * 1024:
            self.log_file.close()
            self.log_file = self._get_log_file()
        else:
            try:
                log_msg = {}
                log_msg['timestamp'] = self._get_timestamp_utc_str()
                log_msg['dialog_id'] = dialog_id
                log_msg['direction'] = direction
                log_msg['message'] = utterance
                log_str = json.dumps(log_msg, ensure_ascii=self.config['ensure_ascii'])
                self.log_file.write(f'{log_str}\n')
            except IOError:
                log.error('Failed to write dialog log.')
def _log(self, utterance: Any, direction: str, dialog_id: Optional[Hashable]=None):
        if isinstance(utterance, str):
            pass
        elif isinstance(utterance, RichMessage):
            utterance = utterance.json()
        elif isinstance(utterance, (list, dict)):
            utterance = jsonify_data(utterance)
        else:
            utterance = str(utterance)

        dialog_id = str(dialog_id) if not isinstance(dialog_id, str) else dialog_id

        if self.log_file.tell() >= self.log_max_size * 1024:
            self.log_file.close()
            self.log_file = self._get_log_file()
        else:
            try:
                log_msg = {}
                log_msg['timestamp'] = self._get_timestamp_utc_str()
                log_msg['dialog_id'] = dialog_id
                log_msg['direction'] = direction
                log_msg['message'] = utterance
                log_str = json.dumps(log_msg, ensure_ascii=self.config['ensure_ascii'])
                self.log_file.write(f'{log_str}\n')
            except IOError:
                log.error('Failed to write dialog log.')
def _log ( self , utterance : Any , direction : str , dialog_id : Optional [ Hashable ] = None ) : if isinstance ( utterance , str ) : pass elif isinstance ( utterance , RichMessage ) : utterance = utterance . json ( ) elif isinstance ( utterance , ( list , dict ) ) : utterance = jsonify_data ( utterance ) else : utterance = str ( utterance ) dialog_id = str ( dialog_id ) if not isinstance ( dialog_id , str ) else dialog_id if self . log_file . tell ( ) >= self . log_max_size * 1024 : self . log_file . close ( ) self . log_file = self . _get_log_file ( ) else : try : log_msg = { } log_msg [ 'timestamp' ] = self . _get_timestamp_utc_str ( ) log_msg [ 'dialog_id' ] = dialog_id log_msg [ 'direction' ] = direction log_msg [ 'message' ] = utterance log_str = json . dumps ( log_msg , ensure_ascii = self . config [ 'ensure_ascii' ] ) self . log_file . write ( f'{log_str}\n' ) except IOError : log . error ( 'Failed to write dialog log.' )
Logs single dialog utterance to current dialog log file.

        Args:
            utterance: Dialog utterance.
            direction: 'in' or 'out' utterance direction.
            dialog_id: Dialog ID.
Logs single dialog utterance to current dialog log file .