log this information to syslog or user provided logfile.
968552
def log(self, msg, level="info"):
        
        if not self.config.get("log_file"):
            # If level was given as a str then convert to actual level
            level = LOG_LEVELS.get(level, level)
            syslog(level, u"{}".format(msg))
        else:
            # Binary mode so fs encoding setting is not an issue
            with open(self.config["log_file"], "ab") as f:
                log_time = time.strftime("%Y-%m-%d %H:%M:%S")
                # nice formating of data structures using pretty print
                if isinstance(msg, (dict, list, set, tuple)):
                    msg = pformat(msg)
                    # if multiline then start the data output on a fresh line
                    # to aid readability.
                    if "\n" in msg:
                        msg = u"\n" + msg
                out = u"{} {} {}\n".format(log_time, level.upper(), msg)
                try:
                    # Encode unicode strings to bytes
                    f.write(out.encode("utf-8"))
                except (AttributeError, UnicodeDecodeError):
                    # Write any byte strings straight to log
                    f.write(out)
570138
def log(self, msg, error=False):
        """"""
        output = self.stdout
        if error:
            output = self.stderr

        output.write(msg)
        output.write('\n')
984525
def _write_to_log(self, output):
        """"""
        with open(self.log_file, 'a') as log_file:
            log_file.write('\n')
            log_file.write(output)
            log_file.write('\n')
1115700
def log(self, *args):
        """"""
        if _canShortcutLogging(self.logCategory, LOG):
            return
        logObject(self.logObjectName(), self.logCategory,
            *self.logFunction(*args))
51842
def use_absl_log_file(self, program_name=None, log_dir=None):
    """"""
    if FLAGS['logtostderr'].value:
      self.stream = sys.stderr
    else:
      self.start_logging_to_file(program_name=program_name, log_dir=log_dir)
175330
def start(self):
        """"""

        if self.log_filename:
            print('Output will be logged to `%s`.' % self.log_filename)

        start_time = time.strftime(self.timestamp_fmt)
        print('Started %s' % start_time)

        if self.log_filename:
            orig_stdout = sys.stdout
            orig_stderr = sys.stderr

            sys.stdout = self.log_file
            sys.stderr = self.log_file

            print('Started %s' % start_time)

        doit_main = DoitMain(self)
        doit_main.run(['run'])

        stop_time = time.strftime(self.timestamp_fmt)

        if self.log_filename:
            print('Stopped %s' % stop_time)
            print()

            sys.stdout = orig_stdout
            sys.stderr = orig_stderr
            self.log_file.close()

        print('Stopped %s' % stop_time)
1189282
def logSysInfo():
    """"""
    logger.info('#' * 70)
    logger.info(datetime.today().strftime("%A, %d %B %Y %I:%M%p"))
    logger.info('Running on [{0}] [{1}]'.format(platform.node(),
                                                platform.platform()))
    logger.info('Python [{0}]'.format(sys.version))
    logger.info('#' * 70 + '\n')
220933
def _log(self, s):
    """
    # TODO(tewalds): Should this be using logging.info instead? How to see them
    # outside of google infrastructure?
    sys.stderr.write(s)
    sys.stderr.flush()
126797
def get_syslog(self, service_id, version_number, name):
		""""""
		content = self._fetch("/service/%s/version/%d/syslog/%s" % (service_id, version_number, name))
		return FastlySyslog(self, content)
1093183
def log_if(level, msg, condition, *args):
  """"""
  if condition:
    log(level, msg, *args)
31676
def log(self, *msg, sep='', end='\n', flush=False):
        """"""
        if not self.quiet:
            print(*msg, sep=sep, end=end, flush=flush)
676754
def _log(self, fname, txt, prg=''):
        
        if os.sep not in fname:
            fname = self.log_folder + os.sep + fname
        delim = ','
        q = '"'
        dte = TodayAsString()
        usr = GetUserName()
        hst = GetHostName()
        i = self.session_id
 
        if prg == '':
            prg = 'cls_log.log' 
        logEntry = q + dte + q + delim + q + i + q + delim + q + usr + q + delim + q + hst + q + delim + q + prg + q + delim + q + txt + q + delim + '\n'
        with open(fname, "a", encoding='utf-8', errors='replace') as myfile:
            myfile.write(logEntry)
1194114
private void openLog()
  {
    closeLogStream();

    WriteStream os = _os;
    _os = null;

    IoUtil.close(os);

    Path path = getPath();

    if (path == null) {
      path = getPath(CurrentTime.currentTime());
    }

    Path parent = path.getParent();

    try {
      if (! Files.isDirectory(parent)) {
        Files.createDirectory(parent);
      }
    } catch (Exception e) {
      logWarning(L.l("Can't create log directory {0}.\n  Exception={1}",
                     parent, e), e);
    }

    Exception exn = null;

    for (int i = 0; i < 3 && _os == null; i++) {
      try {
        OutputStream out = Files.newOutputStream(path, StandardOpenOption.APPEND);
        _os = new WriteStream(out);
      } catch (IOException e) {
        exn = e;
      }
    }

    String pathName = path.toString();

    try {
      if (pathName.endsWith(".gz")) {
        _zipOut = _os;
        _os = new WriteStream(new GZIPOutputStream(_zipOut));
      }
      else if (pathName.endsWith(".zip")) {
        throw new ConfigException("Can't support .zip in path-format");
      }
    } catch (Exception e) {
      if (exn == null)
        exn = e;
    }

    if (exn != null)
      logWarning(L.l("Can't create log for {0}.\n  User={1} Exception={2}",
                     path, System.getProperty("user.name"), exn), exn);
  }
387023
def start_logging(log_file='', log_level='INFO', verbose=False):
    
    if not log_file:
        # create log directory if it doesn't exist
        log_dir = os.path.abspath('log') + '/'
        if not os.path.isdir(log_dir):
            os.mkdir(log_dir)

        # path to new log file
        log_file = log_dir + 'log.run.' + str(datetime.datetime.now()).replace(':', '.') + '.txt'

    # logger options
    lvl = logging.DEBUG if log_level.upper() == 'DEBUG' else logging.INFO

    # ignore warnings if not in debug
    if log_level.upper() != 'DEBUG':
        warnings.filterwarnings('ignore')

    # define logging format
    if verbose:
        myformat = '%(asctime)s - %(name)s - %(levelname)s \n>>>  %(message)s'
    else:
        myformat = '%(message)s'

    # create logger
    if not log_file == 'stdout':
        # normal logging to a regular file
        logging.basicConfig(level=lvl,
                            format=myformat,
                            filename=log_file,
                            filemode='w')
    else:
        # logging to stdout
        root = logging.getLogger()
        root.setLevel(lvl)
        stdout_stream = logging.StreamHandler(sys.stdout)
        stdout_stream.setLevel(lvl)
        formatter = logging.Formatter(myformat)
        stdout_stream.setFormatter(formatter)
        root.addHandler(stdout_stream)
        root.propagate = True
826474
def _write_to_log(self, s, truncate=False):
        """"""
        # if truncate is True, set write mode to truncate
        with open(self._logfile, 'w' if truncate else 'a') as fp:
            fp.writelines((to_text(s) if six.PY2 else to_text(s), ))
1234142
def initialise_logging(level: str, target: str, short_format: bool):
    """"""
    try:
        log_level = getattr(logging, level)
    except AttributeError:
        raise SystemExit(
            "invalid log level %r, expected any of 'DEBUG', 'INFO', 'WARNING', 'ERROR' or 'CRITICAL'" % level
        )
    handler = create_handler(target=target)
    logging.basicConfig(
        level=log_level,
        format='%(asctime)-15s (%(process)d) %(message)s' if not short_format else '%(message)s',
        datefmt='%Y-%m-%d %H:%M:%S',
        handlers=[handler]
    )
150462
def log(self, level, prefix = ''):
        
        logging.log(level, "%sname: %s", prefix, self.__name)
        logging.log(level, "%soptions: %s", prefix, self.__options)