convert a tlog to a .m file
544360
def process_tlog(filename):
    ''''''

    print("Processing %s" % filename)

    mlog = mavutil.mavlink_connection(filename, dialect=args.dialect, zero_time_base=True)

    # first walk the entire file, grabbing all messages into a hash of lists,
    #and the first message of each type into a hash
    msg_types = {}
    msg_lists = {}

    types = args.types
    if types is not None:
        types = types.split(',')

    # note that Octave doesn't like any extra '.', '*', '-', characters in the filename
    (head, tail) = os.path.split(filename)
    basename = '.'.join(tail.split('.')[:-1])
    mfilename = re.sub('[\.\-\+\*]','_', basename) + '.m'
    # Octave also doesn't like files that don't start with a letter
    if (re.match('^[a-zA-z]', mfilename) == None):
        mfilename = 'm_' + mfilename

    if head is not None:
        mfilename = os.path.join(head, mfilename)
    print("Creating %s" % mfilename)

    f = open(mfilename, "w")

    type_counters = {}

    while True:
        m = mlog.recv_match(condition=args.condition)
        if m is None:
            break

        if types is not None and m.get_type() not in types:
            continue
        if m.get_type() == 'BAD_DATA':
            continue

        fieldnames = m._fieldnames
        mtype = m.get_type()
        if mtype in ['FMT', 'PARM']:
            continue

        if mtype not in type_counters:
            type_counters[mtype] = 0
            f.write("%s.columns = {'timestamp'" % mtype)
            for field in fieldnames:
                val = getattr(m, field)
                if not isinstance(val, str):
                    if type(val) is not list:
                        f.write(",'%s'" % field)
                    else:
                        for i in range(0, len(val)):
                            f.write(",'%s%d'" % (field, i + 1))
            f.write("};\n")

        type_counters[mtype] += 1
        f.write("%s.data(%u,:) = [%f" % (mtype, type_counters[mtype], m._timestamp))
        for field in m._fieldnames:
            val = getattr(m, field)
            if not isinstance(val, str):
                if type(val) is not list:
                    f.write(",%.20g" % val)
                else:
                    for i in range(0, len(val)):
                        f.write(",%.20g" % val[i])
        f.write("];\n")
    f.close()
1325612
private static String formatLogParam(Blob obj) {
		String result="";
		try {
			result= "(blob of length "+obj.length()+")";
		} catch (SQLException e) {
			result = "(blob of unknown length)";
		}
		return result;
	}
559047
def logpt(self, t, xp, x):
        """"""
        return self.ssm.PX(t, xp).logpdf(x)
1089563
def handle_log_data(self, m):
        ''''''
        if self.download_file is None:
            return
        # lose some data
        # import random
        # if random.uniform(0,1) < 0.05:
        #    print('dropping ', str(m))
        #    return
        if m.ofs != self.download_ofs:
            self.download_file.seek(m.ofs)
            self.download_ofs = m.ofs
        if m.count != 0:
            data = m.data[:m.count]
            s = ''.join(str(chr(x)) for x in data)
            self.download_file.write(s)
            self.download_set.add(m.ofs // 90)
            self.download_ofs += m.count
        self.download_last_timestamp = time.time()
        if m.count == 0 or (m.count < 90 and len(self.download_set) == 1 + (m.ofs // 90)):
            dt = time.time() - self.download_start
            self.download_file.close()
            size = os.path.getsize(self.download_filename)
            speed = size / (1000.0 * dt)
            print("Finished downloading %s (%u bytes %u seconds, %.1f kbyte/sec %u retries)" % (
                self.download_filename,
                size,
                dt, speed,
                self.retries))
            self.download_file = None
            self.download_filename = None
            self.download_set = set()
929592
def dump_to_log(self, logger):
        """"""
        logger.error("Execution ended in %s for cmd %s", self._retcode, self._cmd)
        for line in self._collected_stdout:
            logger.error(STDOUT_LOG_PREFIX + line)
935190
def log_to_file(filename, level=DEBUG):
    """"""
    l = logging.getLogger("paramiko")
    if len(l.handlers) > 0:
        return
    l.setLevel(level)
    f = open(filename, 'w')
    lh = logging.StreamHandler(f)
    lh.setFormatter(logging.Formatter('%(levelname)-.3s [%(asctime)s.%(msecs)03d] thr=%(_threadid)-3d %(name)s: %(message)s',
                                      '%Y%m%d-%H:%M:%S'))
    l.addHandler(lh)
833025
def dump(self):
        """"""

        for i in range(0, len(self.TA)):
            if self.TA[i] is not None:
                print("TA%d: %x" % (i + 1, self.TA[i]))
            if self.TB[i] is not None:
                print("TB%d: %x" % (i + 1, self.TB[i]))
            if self.TC[i] is not None:
                print("TC%d: %x" % (i + 1, self.TC[i]))
            if self.TD[i] is not None:
                print("TD%d: %x" % (i + 1, self.TD[i]))

        print('supported protocols ' + ','.join(self.getSupportedProtocols()))
        print('T=0 supported: ' + str(self.isT0Supported()))
        print('T=1 supported: ' + str(self.isT1Supported()))

        if self.getChecksum():
            print('checksum: %d' % self.getChecksum())

        print('\tclock rate conversion factor: ' +
              str(self.getClockRateConversion()))
        print('\tbit rate adjustment factor: ' + str(self.getBitRateFactor()))

        print('\tmaximum programming current: ' +
              str(self.getProgrammingCurrent()))
        print('\tprogramming voltage: ' + str(self.getProgrammingVoltage()))

        print('\tguard time: ' + str(self.getGuardTime()))

        print('nb of interface bytes: %d' % self.getInterfaceBytesCount())
        print('nb of historical bytes: %d' % self.getHistoricalBytesCount())
280991
def to_string(self, metadata=False):
        """"""
        return "\n".join(rec.get_message(metadata=metadata) for rec in self)
1365074
def save_log_to_html(self):
        """"""
        html = html_header()
        html += (
            '<img src="file:///%s/img/logos/inasafe-logo-url.png" '
            'title="InaSAFE Logo" alt="InaSAFE Logo" />' % resources_path())
        html += ('<h5 class="info"><i class="icon-info-sign icon-white"></i> '
                 '%s</h5>' % self.tr('Analysis log'))
        for item in self.dynamic_messages_log:
            html += "%s\n" % item.to_html()
        html += html_footer()
        if self.log_path is not None:
            html_to_file(html, self.log_path)
        else:
            msg = self.tr('log_path is not set')
            raise InvalidParameterError(msg)
348024
def readTFAM(fileName):
    
    # Saving the TFAM file
    tfam = None
    with open(fileName, 'r') as inputFile:
        tfam = [
            tuple(i.rstrip("\r\n").split("\t")) for i in inputFile.readlines()
        ]

    tfam = np.array(tfam)

    return tfam
569746
def copy_root_log_to_file(filename: str,
                          fmt: str = LOG_FORMAT,
                          datefmt: str = LOG_DATEFMT) -> None:
    
    fh = logging.FileHandler(filename)
    # default file mode is 'a' for append
    formatter = logging.Formatter(fmt=fmt, datefmt=datefmt)
    fh.setFormatter(formatter)
    apply_handler_to_root_log(fh)
171819
def _log_to_file(self, etype, source, msg='', target='', hostmask='', params=''):
        
        today = datetime.utcnow()
        # TODO: Use self.locale['timezone'] for changing time
        date = today.strftime(self.locale['date_fmt'])
        time = today.strftime(self.locale['time_fmt'])
        datetime_s = today.strftime(self.locale['short_datetime_fmt'])
        datetime_l = today.strftime(self.locale['long_datetime_fmt'])
        
        if target == self.nickname and etype in ('privmsg', 'action'):
            target = source

        if etype in self.log_formats:
            file_path = os.path.expanduser(self.log_file.format(**locals()))
            file_dir = os.path.dirname(file_path)
            if not os.path.isdir(file_dir):
                os.makedirs(file_dir)

            line = self.log_formats[etype].format(**locals())
            with open(file_path, 'a') as log:
                log.write(line+'\n')
795425
def start_logging_to_file(self, program_name=None, log_dir=None):
    """"""
    FLAGS.logtostderr = False

    actual_log_dir, file_prefix, symlink_prefix = find_log_dir_and_names(
        program_name=program_name, log_dir=log_dir)

    basename = '%s.INFO.%s.%d' % (
        file_prefix,
        time.strftime('%Y%m%d-%H%M%S', time.localtime(time.time())),
        os.getpid())
    filename = os.path.join(actual_log_dir, basename)

    if six.PY2:
      self.stream = open(filename, 'a')
    else:
      self.stream = open(filename, 'a', encoding='utf-8')

    # os.symlink is not available on Windows Python 2.
    if getattr(os, 'symlink', None):
      # Create a symlink to the log file with a canonical name.
      symlink = os.path.join(actual_log_dir, symlink_prefix + '.INFO')
      try:
        if os.path.islink(symlink):
          os.unlink(symlink)
        os.symlink(os.path.basename(filename), symlink)
      except EnvironmentError:
        # If it fails, we're sad but it's no error.  Commonly, this
        # fails because the symlink was created by another user and so
        # we can't modify it
        pass
885595
def set_up_logging(log_filename: str = "log", verbosity: int = 0) ->logging.Logger:
    """"""
    LOG.setLevel(logging.DEBUG)

    # Log everything verbosely to a file.
    file_handler = RotatingFileHandler(filename=log_filename, maxBytes=1024000000, backupCount=10)
    verbose_form = logging.Formatter(fmt="%(asctime)s - %(levelname)s - %(module)s - %(message)s")
    file_handler.setFormatter(verbose_form)
    file_handler.setLevel(logging.DEBUG)
    LOG.addHandler(file_handler)

    # Provide a stdout handler logging at INFO.
    stream_handler = logging.StreamHandler(sys.stdout)
    simple_form = logging.Formatter(fmt="%(message)s")
    stream_handler.setFormatter(simple_form)

    if verbosity > 0:
        stream_handler.setLevel(logging.DEBUG)
    else:
        stream_handler.setLevel(logging.INFO)

    LOG.addHandler(stream_handler)

    return LOG
1139943
def printTemporalMemory(tm, outFile):
  
  table = PrettyTable(["Parameter name", "Value", ])

  table.add_row(["columnDimensions", tm.getColumnDimensions()])
  table.add_row(["cellsPerColumn", tm.getCellsPerColumn()])
  table.add_row(["activationThreshold", tm.getActivationThreshold()])
  table.add_row(["minThreshold", tm.getMinThreshold()])
  table.add_row(["maxNewSynapseCount", tm.getMaxNewSynapseCount()])
  table.add_row(["permanenceIncrement", tm.getPermanenceIncrement()])
  table.add_row(["permanenceDecrement", tm.getPermanenceDecrement()])
  table.add_row(["initialPermanence", tm.getInitialPermanence()])
  table.add_row(["connectedPermanence", tm.getConnectedPermanence()])
  table.add_row(["predictedSegmentDecrement", tm.getPredictedSegmentDecrement()])

  print >>outFile, table.get_string().encode("utf-8")
858546
static void printToLogFile(String str) {
    try (BufferedWriter bw = new BufferedWriter(new FileWriter(getLogPath(), true))) {
      bw.write(str + logLineBreak);
    } catch (Throwable t) {
      showError(t);
    }
  }
1223358
def parse_logs(self, f):
        """"""
        data = {}
        for l in f.splitlines():
            # catch empty lines
            if len(l) == 0:
                continue
            s = l.split("\t")
            data_ = []
            # catch lines with descriptive content: "Of pairs used:"
            for i in s[1:]:
                if len(i) == 0:
                    continue
                try:
                    i.replace('(', '')
                    i.replace(')', '')
                    i.replace(',', '')

                    data_.append(float(i))
                except ValueError:
                    data_.append(i)
            if len(data_) == 0:
                continue
            if s[0].startswith('short range'):
                s[0] = 'short range'
            elif s[0].startswith('same fragment'):
                s[0] = 'same fragment'
            s[0] = s[0].capitalize()
            data[s[0]] = data_
        return data