Preprocess/cleanup a bzr log message before parsing

        Args:
            s (str): log message string
            by (int): cutoff threshold for log message length

        Returns:
            str: preprocessed log message string
556098
def _logmessage_transform(cls, s, by=2):
        
        if len(s) >= by:
            return s[by:].strip('\n')
        return s.strip('\n')
1025721
def _processMsg(self, type, msg):
        
        now = datetime.datetime.now()

        # Check If Path not provided
        if self.LOG_FILE_PATH == '':
            self.LOG_FILE_PATH = os.path.dirname(os.path.abspath(__file__)) + '/'

        # Build absolute Path
        log_file = self.LOG_FILE_PATH + now.strftime(self.LOG_FILE_FORMAT) + '.log'
        
        # Add General Vars
        msg = self.LOG_MESSAGE_FORMAT.format(
            TYPE=type.upper(),
            DATE=now.strftime(self.DATES_FORMAT),
            DATETIME=now.strftime(self.DATETIME_FORMAT),
            MESSAGE=msg,
        )

        # Check if to add platform data
        if self.PLATFORM_DATA:
            # Add Platform Specific Vars
            msg = msg.format(
                PL_TYPE=platform.machine(),
                PL_NAME=platform.node(),
                PL_PROCESSOR=platform.processor(),
                PL_PY_BUILD_DATE=platform.python_build()[1],
                PL_PY_COMPILER=platform.python_compiler(),
                PL_PY_RELEASE=platform.release(),
                PL_OS=platform.system(),
                PL_TIMEZONE=strftime("%z", gmtime())
            )

        # Create Storage Instance
        self._STORAGE = Storage(log_file)
        # Write Storage
        return self._STORAGE.write(msg)
1170125
def split_msg(msgs: List[bytes], max_len: int) -> Tuple[str, List[bytes]]:
    """"""
    msg = ""
    while len(msg.encode()) < max_len:
        if len(msg.encode()) + len(msgs[0]) > max_len:
            return msg, msgs
        char = msgs.pop(0).decode()
        # If we have a space within 15 chars of the length limit, split there to avoid words being broken up.
        if char == " " and len(msg.encode()) > max_len - 15:
            return msg, msgs
        msg += char
    return msg, msgs
675273
def _log_control(self, s):
        """"""
        if self.encoding is not None:
            s = s.decode(self.encoding, 'replace')
        self._log(s, 'send')
462178
def log_(
    message: str,
    logger: logging.Logger,
    level: str = "info",
    extra: Optional[Dict] = None,
    trim: bool = False,
) -> None:
    
    if extra is None:
        extra = {}
    # Clean up the message for logging
    if message:
        message = message.replace("\n", "").replace("  ", " ").replace("{ ", "{")
    if trim:
        message = _trim_message(message)
    # Log.
    getattr(logger, level)(message, extra=extra)
533325
def capture_log_messages( opts = {} )
      from = opts.fetch(:from, 'root')
      to = opts.fetch(:to, '__rspec__')
      exclusive = opts.fetch(:exclusive, true)

      appender = Logging::Appenders[to] || Logging::Appenders::StringIo.new(to)
      logger = Logging::Logger[from]
      if exclusive
        logger.appenders = appender
      else
        logger.add_appenders(appender)
      end

      before(:all) do
        @log_output = Logging::Appenders[to]
      end

      before(:each) do
        @log_output.reset
      end
    end
296279
def format_logstash_v0(self, record):
        '''
        
        '''
        host = salt.utils.network.get_fqhostname()
        message_dict = {
            '@timestamp': self.formatTime(record),
            '@fields': {
                'levelname': record.levelname,
                'logger': record.name,
                'lineno': record.lineno,
                'pathname': record.pathname,
                'process': record.process,
                'threadName': record.threadName,
                'funcName': record.funcName,
                'processName': record.processName
            },
            '@message': record.getMessage(),
            '@source': '{0}://{1}/{2}'.format(
                self.msg_type,
                host,
                self.msg_path
            ),
            '@source_host': host,
            '@source_path': self.msg_path,
            '@tags': self.tags,
            '@type': self.msg_type,
        }

        if record.exc_info:
            message_dict['@fields']['exc_info'] = self.formatException(
                record.exc_info
            )

        # Add any extra attributes to the message field
        for key, value in six.iteritems(record.__dict__):
            if key in ('args', 'asctime', 'created', 'exc_info', 'exc_text',
                       'filename', 'funcName', 'id', 'levelname', 'levelno',
                       'lineno', 'module', 'msecs', 'msecs', 'message', 'msg',
                       'name', 'pathname', 'process', 'processName',
                       'relativeCreated', 'thread', 'threadName'):
                # These are already handled above or not handled at all
                continue

            if value is None:
                message_dict['@fields'][key] = value
                continue

            if isinstance(value, (six.string_types, bool, dict, float, int, list)):
                message_dict['@fields'][key] = value
                continue

            message_dict['@fields'][key] = repr(value)
        return message_dict
436734
function Logger_clean(message) {
            if (Type.isString(message)) {
                replace.forEach(function (value) {
                    message = message.replace(value, '');
                });
                message = message.replace(/\\'/g, "'");
                message = message.replace(/\\n/g, "\n");
                return message.replace(/\\u001b/g, '\u001b');
            }
            return message;
        }
900523
def parse_band_log(self, message):
        """"""
        if "payload" in message and hasattr(message["payload"], "name"):
            record = message["payload"]
            for k in dir(record):
                if k.startswith("workflows_exc_"):
                    setattr(record, k[14:], getattr(record, k))
                    delattr(record, k)
            for k, v in self.get_status().items():
                setattr(record, "workflows_" + k, v)
            logging.getLogger(record.name).handle(record)
        else:
            self.log.warning(
                "Received broken record on log band\n" + "Message: %s\nRecord: %s",
                str(message),
                str(
                    hasattr(message.get("payload"), "__dict__")
                    and message["payload"].__dict__
                ),
            )
293868
def _parse(self, msg_dict):
        '''
        
        '''
        error_present = False
        # log.debug('Matching the message:')
        # log.debug(msg_dict)
        for message in self.compiled_messages:
            # log.debug('Matching using:')
            # log.debug(message)
            match_on = message['match_on']
            if match_on not in msg_dict:
                # log.debug('%s is not a valid key in the partially parsed dict', match_on)
                continue
            if message['tag'] != msg_dict[match_on]:
                continue
            if '__python_fun__' in message:
                return {
                    'model': message['model'],
                    'error': message['error'],
                    '__python_fun__': message['__python_fun__']
                }
            error_present = True
            match = message['line'].search(msg_dict['message'])
            if not match:
                continue
            positions = message.get('positions', {})
            values = message.get('values')
            ret = {
                'model': message['model'],
                'mapping': message['mapping'],
                'replace': message['replace'],
                'error': message['error']
            }
            for key in values.keys():
                # Check if the value needs to be replaced
                if key in message['replace']:
                    result = napalm_logs.utils.cast(match.group(positions.get(key)), message['replace'][key])
                else:
                    result = match.group(positions.get(key))
                ret[key] = result
            return ret
        if error_present is True:
            log.info('Configured regex did not match for os: %s tag %s', self._name, msg_dict.get('tag', ''))
        else:
            log.info('Syslog message not configured for os: %s tag %s', self._name, msg_dict.get('tag', ''))
461384
def decode_sent_msg(pref, message, pretty=False):
    
    newline = "\n" if pretty else " "
    indent = "    " if pretty else ""
    start = newline + indent

    out = []
    out.append("%s%s{%sSEQNUM: %d," % (pref, newline, start, message[Const.W_SEQ]))
    out.append("%sCOMPRESSION: %d," % (start, message[Const.W_COMPRESSION]))
    out.append("%sHASH: %s...," % (start, str(binascii.b2a_hex(message[Const.W_HASH]).decode('ascii'))[:10]))
    out.append("%sMESSAGE:%s{%sCLIENTREF: %s," % (start, start, start + indent,
                                                  message[Const.W_MESSAGE][Const.M_CLIENTREF]))
    out.append("%sRESOURCE: %s," % (start + indent, R_TYPES[message[Const.W_MESSAGE][Const.M_RESOURCE]]))
    out.append("%sTYPE: %s," % (start + indent, C_TYPES[message[Const.W_MESSAGE][Const.M_TYPE]]))
    out.append("%sACTION: %s," % (start + indent, message[Const.W_MESSAGE][Const.M_ACTION]))
    if Const.M_RANGE in message[Const.W_MESSAGE]:
        out.append("%sRANGE: %s," % (start + indent, message[Const.W_MESSAGE][Const.M_RANGE]))
    out.append("%sPAYLOAD: %s%s}%s}" % (start + indent, message[Const.W_MESSAGE][Const.M_PAYLOAD], start, newline))

    return ''.join(out)
1343159
def parse(self, rrstr):
        # type: (bytes) -> None
        '''
        
        '''
        if self._initialized:
            raise pycdlibexception.PyCdlibInternalError('ST record already initialized!')

        (su_len, su_entry_version_unused) = struct.unpack_from('=BB', rrstr[:4], 2)

        # We assume that the caller has already checked the su_entry_version,
        # so we don't bother.

        if su_len != 4:
            raise pycdlibexception.PyCdlibInvalidISO('Invalid length on rock ridge extension')

        self._initialized = True
737138
def to_s
      log_time=event_time.strftime(CEF::LOG_TIME_FORMAT)
      
      sprintf(
        CEF::LOG_FORMAT,
        syslog_pri.to_s,
        log_time,
        my_hostname,
        format_prefix,
        format_extension
      )
    end
479747
def spliceext(filepath, s):
    
    root, ext = os.path.splitext(safepath(filepath))
    return root + s + ext
20263
def message_from_bytes(s, *args, **kws):
    
    from future.backports.email.parser import BytesParser
    return BytesParser(*args, **kws).parsebytes(s)
751963
def parse(self, s):
        
        return datetime.datetime.strptime(s, self.date_format).date()
926268
def to_s
      message = ''
      @messages.keys.sort.each do |timestamp|
        message << "#{Time.at(timestamp / 1000)}"
        message << " #{@messages[timestamp]['severity']}: #{@messages[timestamp]['user']}:"
        message << " #{@messages[timestamp]['short-description']}"
        unless @messages[timestamp]['short-description'].eql?(@messages[timestamp]['long-description'])
          message << "; #{@messages[timestamp]['long-description']}"
        end
        message << "\n"
      end
      message
    end