*Create a MD log of the survey settings*

    **Key Arguments:**
        - ``log`` -- logger
        - ``pathToYamlFile`` -- yaml results file

    **Return:**
        - None
188253
def log_the_survey_settings(
        log,
        pathToYamlFile):
    
    ################ > IMPORTS ################
    ## STANDARD LIB ##
    ## THIRD PARTY ##
    import yaml
    ## LOCAL APPLICATION ##
    from datetime import datetime, date, time
    now = datetime.now()
    now = now.strftime("%Y%m%dt%H%M%S")

    ################ >ACTION(S) ################
    # IMPORT THE SIMULATION SETTINGS
    fileName = pathToYamlFile
    stream = file(fileName, 'r')
    yamlContent = yaml.load(stream)
    snSurveyDiscoveryTimes = yamlContent['Discoveries Relative to Survey Year']
    lightCurveDiscoveryTimes = yamlContent[
        'Discoveries Relative to Peak Magnitudes']
    snTypes = yamlContent['SN Types']
    redshifts = yamlContent['Redshifts']
    cadenceDictionary = yamlContent['Cadence Dictionary']
    peakAppMagList = yamlContent['Peak Apparent Magnitudes']
    snCampaignLengthList = yamlContent['Campaign Length']

    programSettings = yamlContent["Program Settings"]

    limitingMags = yamlContent["Limiting Magnitudes"]
    # for key in limitingMags:
    # log.debug('filter: %s, limit: %s' % (key, limitingMags[key]))

    sampleNumber = yamlContent["Simulation Sample"]

    peakMagnitudeDistributions = yamlContent[
        "SN Absolute Peak-Magnitude Distributions"]
    #log.debug('snDistributions[magnitude] %s' % (snDistributions["magnitude"],))
    #log.debug('snDistributions[sigma] %s' % (snDistributions["sigma"],))

    relativeRatesSet = yamlContent["Relative Rate Set to Use"]
    relativeSNRates = yamlContent["Relative SN Rates"][relativeRatesSet]
    #log.debug('relativeSNRates %s' % (relativeSNRates,))
    lowerRedshiftLimit = yamlContent["Lower Redshift Limit"]
    upperRedshiftLimit = yamlContent["Upper Redshift Limit"]
    #log.debug('upperRedshiftLimit %s' % (upperRedshiftLimit,))
    redshiftResolution = yamlContent["Redshift Resolution"]

    extinctionSettings = yamlContent["Extinctions"]
    extinctionType = extinctionSettings["constant or random"]

    hostExtinctionDistributions = extinctionSettings["host"]
    #log.debug('hostExtinctionDistributions %s' % (hostExtinctionDistributions,))
    galacticExtinctionDistribution = extinctionSettings["galactic"]
    #log.debug('galacticExtinctionDistribution %s' % (galacticExtinctionDistribution,))

    surveyCadenceSettings = yamlContent["Survey Cadence"]
    #log.debug('surveyCadenceSettings %s' % (surveyCadenceSettings,))

    snLightCurves = yamlContent["Lightcurves"]
    #log.debug('snlightCurves %s' % (snlightCurves,))

    surveyArea = yamlContent["Sky Area of the Survey (square degrees)"]

    extraSurveyConstraints = yamlContent["Extra Survey Constraints"]

    weatherLossFraction = surveyCadenceSettings[
        "Fraction of Year Lost to Weather etc"]
    observableFraction = surveyCadenceSettings["Observable Fraction of Year"]
    extinctionConstant = extinctionSettings["constant E(b-v)"]
    CCSNRateFraction = yamlContent[
        "CCSN Progenitor Population Fraction of IMF"]
    transientToCCSNRateFraction = yamlContent["Transient to CCSN Ratio"]
    restFrameFilter = yamlContent["Rest Frame Filter for K-corrections"]
    peakMagLimit = extraSurveyConstraints["Faint-Limit of Peak Magnitude"]
    campaignLengthLimit = extraSurveyConstraints[
        "Observable for at least ? number of days"]

    # CALCULATE THE SURVEY VOLUME
    c = converter(log=log)
    dists = c.redshift_to_distance(
        z=float(upperRedshiftLimit),
        WM=0.3,
        WV=0.7,
        H0=70.0
    )
    dl_mpc = dists["dl_mpc"]
    sphereOuter = (4. / 3.) * math.pi * dl_mpc**3

    if float(lowerRedshiftLimit) == 0.:
        surveyVolume = sphereOuter
    else:
        dists = c.redshift_to_distance(
            z=float(lowerRedshiftLimit),
            WM=0.3,
            WV=0.7,
            H0=70.0
        )
        dl_mpc = dists["dl_mpc"]
        sphereInner = (4. / 3.) * math.pi * dl_mpc**3
        surveyVolume = sphereOuter - sphereInner
    # NOW SCALE TO SKY-AREA
    surveyVolume = surveyVolume * surveyArea / 41253
    surveyVolume = surveyVolume / (1000.)**3
    if surveyVolume < 1:
        surveyVolume = "%(surveyVolume)0.4f" % locals()
    elif surveyVolume < 100:
        surveyVolume = "%(surveyVolume)0.2f" % locals()
    else:
        surveyVolume = "%(surveyVolume)0.1f" % locals()

    # CALCULATE OVERALL DETECTION FRACTIONS
    discoveryFraction, tooFaintFraction, shortCampaignFraction = calculate_fraction_of_sn_discovered(
        log, surveyCadenceSettings, snSurveyDiscoveryTimes, redshifts, peakAppMagList, snCampaignLengthList, extraSurveyConstraints, lowerRedshiftLimit, upperRedshiftLimit)

    discoveryFraction = discoveryFraction * 100.
    if discoveryFraction < 1:
        discoveryFraction = "%(discoveryFraction)0.4f" % locals()
    elif discoveryFraction < 10:
        discoveryFraction = "%(discoveryFraction)0.2f" % locals()
    else:
        discoveryFraction = "%(discoveryFraction)0.1f" % locals()

    # log.info('yamlContent %s' % (yamlContent,))
    stream.close()

    settings_log = """
# SN Survey Simulation Results - %s

The *%s*-band liming magnitudes of this simulated survey are:

| Filter | Magnitude |
|:---|:----|
""" % (now, restFrameFilter)
    for k, v in limitingMags.iteritems():
        settings_log += """| %s | %s |\n""" % (k, v,)
    settings_log += """

A total of **%s** transients where simulated in the survey, within a **redshift-range of %s-%s** and **survey footprint of %s deg<sup>2</sup>** (a **total volume of %s Gpc<sup>-3</sup> yr<sup>-1</sup>**). **%s%% of these simulated transients had solid 'discoveries'**.  A constant galactic extinction of `E(B-V) = %s` is used, it's assumed that any given field in the sky is visible for %s of the survey year and the typical fraction of survey time lost to weather of %s is accounted for. Here are the relative rates and peak magnitude distributions of the SN used in the survey:

| SN Type | Relative Rate | Peak Magnitude | Sigma Peak |
|:---|:---|:---|:---|
""" % (sampleNumber, lowerRedshiftLimit, upperRedshiftLimit, surveyArea, surveyVolume, discoveryFraction, extinctionConstant, observableFraction, weatherLossFraction,)
    for k, v in peakMagnitudeDistributions['magnitude'].iteritems():
        settings_log += """| %s | %s | %s | %s |\n""" % (
            k, relativeSNRates[k], v, peakMagnitudeDistributions['sigma'][k])
    settings_log += """

If a transient is detected by the simulated survey, extra constraints are placed upon the detected object to secure positive identification as the object.

1. The peak apparent magnitude of the object must be brighter than **%s mag**
2. The object must be detectable for long enough to complete a follow-up campaign of longer than **%s days** within 1 survey year with any single filter.

The transient rate for the survey volume is estimated by assuming a rate of **%s** times that of the CCSN rate (itself a fraction of **%s** of the total SFR).

""" % (peakMagLimit, campaignLengthLimit, transientToCCSNRateFraction, CCSNRateFraction)
    return settings_log
1318826
def get_log_file(self, api=None):
        
        api = api or self._API
        log_file_data = self.execution_details.get('log_file')
        return File(api=api, **log_file_data) if log_file_data else None
325361
def setup_logging(
    config='logging.yaml',
    default_level=logging.INFO,
    env_key='LOG_CFG'
):
    
    path = config
    value = os.getenv(env_key, None)
    if value:
        path = value

    if path.exists():
        with open(path, 'rt') as f:
            config = yaml.safe_load(f.read())
        logging.config.dictConfig(config)
    else:
        print('cannot read: ' + str(path))
        logging.basicConfig(level=default_level)
188987
def add_scan_log(self, scan_id, host='', name='', value='', port='',
                     test_id='', qod=''):
        
        self.scan_collection.add_result(scan_id, ResultType.LOG, host, name,
                                        value, port, test_id, 0.0, qod)
52217
def _create_logger(name='did', level=None):
        
        # Create logger, handler and formatter
        logger = logging.getLogger(name)
        handler = logging.StreamHandler()
        handler.setFormatter(Logging.ColoredFormatter())
        logger.addHandler(handler)
        # Save log levels in the logger itself (backward compatibility)
        for level in Logging.LEVELS:
            setattr(logger, level, getattr(logging, level))
        # Additional logging constants and methods for details and data
        logger.DATA = LOG_DATA
        logger.DETAILS = LOG_DETAILS
        logger.ALL = LOG_ALL
        logger.details = lambda message: logger.log(
            LOG_DETAILS, message) # NOQA
        logger.data = lambda message: logger.log(
            LOG_DATA, message) # NOQA
        logger.all = lambda message: logger.log(
            LOG_ALL, message) # NOQA
        return logger
1367023
function mdLogEntry(version, log) {
    return util.format(
        '### %s\n%s\n\n',
        version,
        log.map(function (logItem) {
            return '  * ' + logItem;
        }).join('\n')
    );
}
671535
def load_config(logdir):
  # pylint: disable=missing-raises-doc
  
  config_path = logdir and os.path.join(logdir, 'config.yaml')
  if not config_path or not tf.gfile.Exists(config_path):
    message = (
        'Cannot resume an existing run since the logging directory does not '
        'contain a configuration file.')
    raise IOError(message)
  with tf.gfile.FastGFile(config_path, 'r') as file_:
    config = yaml.load(file_, Loader=yaml.Loader)
  message = 'Resume run and write summaries and checkpoints to {}.'
  tf.logging.info(message.format(config.logdir))
  return config
1082069
def generate_output_path(args, project_path):
    
    milisec = datetime.now().microsecond
    dirname = 'results_{}_{}'.format(time.strftime('%Y.%m.%d_%H.%M.%S', time.localtime()), str(milisec))
    return os.path.join(project_path, 'results', dirname)
74441
def cli():
    
    ch = logging.StreamHandler()
    ch.setFormatter(logging.Formatter(
        '%(asctime)s.%(msecs)03d %(levelname)s: %(message)s',
        datefmt="%Y-%m-%d %H:%M:%S"
    ))
    logger.addHandler(ch)

    import argparse
    parser = argparse.ArgumentParser(description="Search 'network' for hosts with a \
    response to 'path' that matches 'filter'")
    parser.add_argument('network', help='IP address with optional mask, e.g. 192.168.0.0/24')
    parser.add_argument('-p', '--path', help='URL path at host, e.g. index.html',
        default='')
    parser.add_argument('-f', '--filter', help='Regular expression pattern for filter',
        dest='pattern', default='')
    parser.add_argument('-l', '--log', help='Enable logging', action='store_true')
    args = parser.parse_args()
    print('Scanning, please wait ...')
    result = survey(**vars(args))
    print('Found {} match{}{}{} on {}'.format(len(result), 'es' if len(result)!=1 else '',
        ' for ' if args.pattern else '', args.pattern, args.network))
    for x in result:
        print(x.hostname)
611792
function buildLogRunTemplate(opts, callback) {
  var viewOpt = {
    logRoot: opts.cmdOptions.log || ('/var/log/' + opts.cmdOptions.app),
    processName: opts.procName,
    num: opts.index,
    user: opts.cmdOptions.user
  };

  renderTemplate(templateFilePath('log_run', opts.templateOpt), viewOpt, function(err, renderedOutput) {
    if (err) {
      return callback(err.message);
    } else {
      return fs.writeFile(opts.processLogRunPath, renderedOutput, function(err) {
	if (err) {
	  return callback(err.message);
	} else {
	  fs.chmodSync(opts.processLogRunPath, 0755);
	  return callback(null);
	}
      });
    }
  });
}
1211542
def log_file(self):
        
        log_file = self.get('log')
        if not log_file:
            log_file = '%s.log' % (self.name)
            self.set('log', log_file)
        return os.path.join(self.initial_dir, self.get('log'))
663266
def save_admin_log(build, **kwargs):
    """"""
    message = kwargs.pop('message', None)
    release = kwargs.pop('release', None)
    run = kwargs.pop('run', None)

    if not len(kwargs) == 1:
        raise TypeError('Must specify a LOG_TYPE argument')

    log_enum = kwargs.keys()[0]
    log_type = getattr(models.AdminLog, log_enum.upper(), None)
    if not log_type:
        raise TypeError('Bad log_type argument: %s' % log_enum)

    if current_user.is_anonymous():
        user_id = None
    else:
        user_id = current_user.get_id()

    log = models.AdminLog(
        build_id=build.id,
        log_type=log_type,
        message=message,
        user_id=user_id)

    if release:
        log.release_id = release.id

    if run:
        log.run_id = run.id
        log.release_id = run.release_id

    db.session.add(log)
137913
private void createLog(File outputDirectory, boolean onlyFailures) throws Exception
    {
        if (!Reporter.getOutput().isEmpty())
        {
            VelocityContext context = createContext();
            context.put(ONLY_FAILURES_KEY, onlyFailures);
            generateFile(new File(outputDirectory, OUTPUT_FILE),
                         OUTPUT_FILE + TEMPLATE_EXTENSION,
                         context);
        }
    }
463598
def define(args, &task_block)
      desc "Generate a Changelog from GitHub"

      yield(*[self, args].slice(0, task_block.arity)) if task_block

      # clear any (auto-)pre-existing task
      Rake::Task[@name].clear if Rake::Task.task_defined?(@name)

      task @name do
        # mimick parse_options
        options = Parser.default_options

        OPTIONS.each do |o|
          v = instance_variable_get("@#{o}")
          options[o.to_sym] = v unless v.nil?
        end
        abort "user and project are required." unless options[:user] && options[:project]
        generator = Generator.new options

        log = generator.compound_changelog

        output_filename = (options[:output]).to_s
        File.open(output_filename, "w") { |file| file.write(log) }
        puts "Done!"
        puts "Generated log placed in #{Dir.pwd}/#{output_filename}"
      end
    end
140357
def create_snapshot(self, xml_bytes):
        
        root = XML(xml_bytes)
        snapshot_id = root.findtext("snapshotId")
        volume_id = root.findtext("volumeId")
        status = root.findtext("status")
        start_time = root.findtext("startTime")
        start_time = datetime.strptime(
            start_time[:19], "%Y-%m-%dT%H:%M:%S")
        progress = root.findtext("progress")[:-1]
        progress = float(progress or "0") / 100.
        return model.Snapshot(
            snapshot_id, volume_id, status, start_time, progress)
902952
def text_log_steps(self, request, project, pk=None):
        
        try:
            job = Job.objects.get(repository__name=project,
                                  id=pk)
        except ObjectDoesNotExist:
            return Response("No job with id: {0}".format(pk), status=HTTP_404_NOT_FOUND)

        textlog_steps = TextLogStep.objects.filter(job=job).order_by(
            'started_line_number').prefetch_related('errors')
        return Response(serializers.TextLogStepSerializer(textlog_steps,
                                                          many=True,
                                                          read_only=True).data)
199983
def setup_logging(config, D=None):
    
    if not D:
        import yaml

        args = config.logging_config
        default = False

        if args.upper() == 'DEFAULT':
            default = True
            src = config.default_logging_file
        else:
            src = args

        # first try to read configured file
        try:
            with open(src) as f:
                D = yaml.load(f)
        except EnvironmentError as ee:
            # fall back to default
            if not default:
                try:
                    with open(config.default_logging_file) as f2:
                        D = yaml.load(f2)
                except EnvironmentError as ee2:
                    raise LoggingConfigurationError('Could not read either configured nor '
                                                    'default logging configuration!\n%s' % ee2)
            else:
                raise LoggingConfigurationError('could not handle default logging '
                                                'configuration file\n%s' % ee)

        if D is None:
            raise LoggingConfigurationError('Empty logging config! Try using default config by'
                                            ' setting logging_conf=DEFAULT in pyemma.cfg')
    assert D

    # this has not been set in PyEMMA version prior 2.0.2+
    D.setdefault('version', 1)
    # if the user has not explicitly disabled other loggers, we (contrary to Pythons
    # default value) do not want to override them.
    D.setdefault('disable_existing_loggers', False)

    # configure using the dict
    try:
        dictConfig(D)
    except ValueError as ve:
        # issue with file handler?
        if 'files' in str(ve) and 'rotating_files' in D['handlers']:
            print("cfg dir", config.cfg_dir)
            new_file = os.path.join(config.cfg_dir, 'pyemma.log')
            warnings.warn("set logfile to %s, because there was"
                          " an error writing to the desired one" % new_file)
            D['handlers']['rotating_files']['filename'] = new_file
        else:
            raise
        dictConfig(D)

    # get log file name of pyemmas root logger
    logger = logging.getLogger('pyemma')
    log_files = [getattr(h, 'baseFilename', None) for h in logger.handlers]

    import atexit
    @atexit.register
    def clean_empty_log_files():
        # gracefully shutdown logging system
        logging.shutdown()
        for f in log_files:
            if f is not None and os.path.exists(f):
                try:
                    if os.stat(f).st_size == 0:
                        os.remove(f)
                except OSError as o:
                    print("during removal of empty logfiles there was a problem: ", o)