Uploads the debug log to cloud storage
324680
def upload_debug(self):
        """"""
        if os.path.exists(self.log_fname):
            api = InternalApi()
            api.set_current_run_id(self.id)
            pusher = FilePusher(api)
            pusher.update_file("wandb-debug.log", self.log_fname)
            pusher.file_changed("wandb-debug.log", self.log_fname)
            pusher.finish()
418876
public static void storeLogs(String sourceLogFileName, String destLogFileName) throws Exception {
        // assumes eventmanager is running
        // store logs
        String tmpdir = System.getProperty("java.io.tmpdir");
        if (tmpdir == null || tmpdir == "null") {
            tmpdir = "/tmp";
        }
    	File tmpLogFile = new File(tmpdir + File.separator + sourceLogFileName);
    	File destFile = new File(current_log_dir + File.separator + destLogFileName);
    	
        Files.copy(tmpLogFile, destFile);
    }
448125
def saveLogs(self, filename) :
		""""""
		f = open(filename, 'wb')
		cPickle.dump(self.logs, f)
		f.close()
1348206
def write_debug_log(self, file_path):
        
        with open(file_path, "wb+") as fh:
            fh.write(system.get_system_info().encode('utf-8'))
            # writing to debug stream
            self._debug_stream.seek(0)
            fh.write(self._debug_stream.read().encode('utf-8'))
            fh.write("The following errors occured:\n".encode('utf-8'))
            for error in self._errors:
                fh.write((error + "\n").encode('utf-8'))
            for k, v in self._error_dict.items():
                if len(v) > 0:
                    fh.write(("Error(s) in %s with formula %s:\n" % k).encode('utf-8'))
                    for error in v:
                        fh.write((error + "\n").encode('utf-8'))
846605
def dump_data(logdir):
  """"""
  # Create a tfevents file in the logdir so it is detected as a run.
  write_empty_event_file(logdir)

  plugin_logdir = plugin_asset_util.PluginDirectory(
      logdir, profile_plugin.ProfilePlugin.plugin_name)
  _maybe_create_directory(plugin_logdir)

  for run in profile_demo_data.RUNS:
    run_dir = os.path.join(plugin_logdir, run)
    _maybe_create_directory(run_dir)
    if run in profile_demo_data.TRACES:
      with open(os.path.join(run_dir, 'trace'), 'w') as f:
        proto = trace_events_pb2.Trace()
        text_format.Merge(profile_demo_data.TRACES[run], proto)
        f.write(proto.SerializeToString())

    if run not in profile_demo_data.TRACE_ONLY:
      shutil.copyfile('tensorboard/plugins/profile/profile_demo.op_profile.json',
                      os.path.join(run_dir, 'op_profile.json'))
      shutil.copyfile(
          'tensorboard/plugins/profile/profile_demo.memory_viewer.json',
          os.path.join(run_dir, 'memory_viewer.json'))
      shutil.copyfile(
          'tensorboard/plugins/profile/profile_demo.pod_viewer.json',
          os.path.join(run_dir, 'pod_viewer.json'))
      shutil.copyfile(
          'tensorboard/plugins/profile/profile_demo.google_chart_demo.json',
          os.path.join(run_dir, 'google_chart_demo.json'))

  # Unsupported tool data should not be displayed.
  run_dir = os.path.join(plugin_logdir, 'empty')
  _maybe_create_directory(run_dir)
  with open(os.path.join(run_dir, 'unsupported'), 'w') as f:
    f.write('unsupported data')
459050
def _init_log(level=logging.DEBUG):
    
    log = logging.getLogger(__file__)
    log.setLevel(level)
    handler = logging.StreamHandler(sys.stdout)
    handler.setLevel(level)
    formatter = logging.Formatter('%(asctime)s: %(message)s',
                                  '%Y/%m/%d-%H:%M:%S')
    handler.setFormatter(formatter)
    log.addHandler(handler)
    return log
587509
public static function dump($debug_backtrace)
    {
        if (PHP_SAPI === 'cli') {
            self::cliDump($debug_backtrace);
        }

        ob_end_clean();
        ob_start();
        echo <<<END
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.0.0/highlight.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.0.0/styles/default.min.css" />
<script>hljs.initHighlightingOnLoad();</script>
<style>code.php.hljs{margin: -0.4em 0;}code.active{background-color:#e0e0e0;}code:before{content:attr(data-line);}code.active:before{color:#c00;font-weight:bold;}</style>
</head>
<body>
END;

        echo '<div>Dump: ' . $debug_backtrace['file'] . ':<b>' . $debug_backtrace['line'] . "</b></div>";
        echo '<pre>';
        $i = 0;
        foreach ($debug_backtrace['args'] as $data) {
            echo '<code>';
            var_dump($data);
            echo '</code>';
            $i += 1;
        }
        echo '</pre>';
        echo <<<END
</body>
</html>
END;
        exit;
    }
810102
function logSetup() {
    JuttleLogger.getLogger = log4js.getLogger;

    let levels = {
        '[all]': 'info'
    };

    // Handle node.js style debug configuration where DEBUG is a
    // comma-separated list of debug targets, or '*' to enable all
    // debugging.
    let DEBUG = process.env.DEBUG;
    if (DEBUG) {
        let targets = DEBUG.split(',');
        _.each(targets, function(target) {
            if (target === '*') { target = '[all]'; }
            levels[target] = 'debug';
        });
    }

    log4js.configure({
        levels: levels,
        appenders: [{type: __dirname + '/stderr-appender'}]
    });

    JuttleLogger.getLogger('cli').debug('set logging levels to', levels);
}
100630
public void upload() {
    try {
      writer.flush();
      if (compress)
        zipCompress(filename);
      String remoteName = "failmon-";
      if ("true".equalsIgnoreCase(Environment.getProperty("anonymizer.hash.hostnames")))
        remoteName += Anonymizer.getMD5Hash(InetAddress.getLocalHost().getCanonicalHostName()) + "-";
      else
        remoteName += InetAddress.getLocalHost().getCanonicalHostName() + "-"; 
      remoteName += Calendar.getInstance().getTimeInMillis();//.toString();
      if (compress)
	copyToHDFS(filename + COMPRESSION_SUFFIX, hdfsDir + "/" + remoteName + COMPRESSION_SUFFIX);
      else
	copyToHDFS(filename, hdfsDir + "/" + remoteName);
    } catch (IOException e) {
      e.printStackTrace();
    }

    // delete and re-open
    try {
      fw.close();
      fw = new FileWriter(filename);
      writer = new BufferedWriter(fw);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
606020
def debugfile(filename, args=None, wdir=None, post_mortem=False):
    
    debugger = pdb.Pdb()
    filename = debugger.canonic(filename)
    debugger._wait_for_mainpyfile = 1
    debugger.mainpyfile = filename
    debugger._user_requested_quit = 0
    if os.name == 'nt':
        filename = filename.replace('\\', '/')
    debugger.run("runfile(%r, args=%r, wdir=%r)" % (filename, args, wdir))
149640
function saveAsIndexedFile(bundle, options, log) {
  const {
    bundleOutput,
    bundleEncoding: encoding,
    sourcemapOutput
  } = options;

  log('start');
  const {startupModules, lazyModules, groups} = bundle.getUnbundle();
  log('finish');

  const moduleGroups = ModuleGroups(groups, lazyModules);
  const startupCode = joinModules(startupModules);

  log('Writing unbundle output to:', bundleOutput);
  const writeUnbundle = writeBuffers(
    fs.createWriteStream(bundleOutput),
    buildTableAndContents(startupCode, lazyModules, moduleGroups, encoding)
  ).then(() => log('Done writing unbundle output'));

  const sourceMap =
    buildSourceMapWithMetaData({startupModules, lazyModules, moduleGroups});

  return Promise.all([
    writeUnbundle,
    writeSourceMap(sourcemapOutput, JSON.stringify(sourceMap), log),
  ]);
}
448031
def log_to_file(filename, level=DEBUG):
    """"""
    logger = logging.getLogger("paramiko")
    if len(logger.handlers) > 0:
        return
    logger.setLevel(level)
    f = open(filename, "a")
    handler = logging.StreamHandler(f)
    frm = "%(levelname)-.3s [%(asctime)s.%(msecs)03d] thr=%(_threadid)-3d"
    frm += " %(name)s: %(message)s"
    handler.setFormatter(logging.Formatter(frm, "%Y%m%d-%H:%M:%S"))
    logger.addHandler(handler)
966866
def deploy_sandbox_shared_setup(log, verbose=True, app=None, exp_config=None):
    """"""
    if verbose:
        out = None
    else:
        out = open(os.devnull, "w")

    config = get_config()
    if not config.ready:
        config.load()
    heroku.sanity_check(config)

    (id, tmp) = setup_experiment(log, debug=False, app=app, exp_config=exp_config)

    # Register the experiment using all configured registration services.
    if config.get("mode") == "live":
        log("Registering the experiment on configured services...")
        registration.register(id, snapshot=None)

    # Log in to Heroku if we aren't already.
    log("Making sure that you are logged in to Heroku.")
    heroku.log_in()
    config.set("heroku_auth_token", heroku.auth_token())
    log("", chevrons=False)

    # Change to temporary directory.
    cwd = os.getcwd()
    os.chdir(tmp)

    # Commit Heroku-specific files to tmp folder's git repo.
    git = GitClient(output=out)
    git.init()
    git.add("--all")
    git.commit('"Experiment {}"'.format(id))

    # Initialize the app on Heroku.
    log("Initializing app on Heroku...")
    team = config.get("heroku_team", None)
    heroku_app = HerokuApp(dallinger_uid=id, output=out, team=team)
    heroku_app.bootstrap()
    heroku_app.buildpack("https://github.com/stomita/heroku-buildpack-phantomjs")

    # Set up add-ons and AWS environment variables.
    database_size = config.get("database_size")
    redis_size = config.get("redis_size")
    addons = [
        "heroku-postgresql:{}".format(quote(database_size)),
        "heroku-redis:{}".format(quote(redis_size)),
        "papertrail",
    ]
    if config.get("sentry"):
        addons.append("sentry")

    for name in addons:
        heroku_app.addon(name)

    heroku_config = {
        "aws_access_key_id": config["aws_access_key_id"],
        "aws_secret_access_key": config["aws_secret_access_key"],
        "aws_region": config["aws_region"],
        "auto_recruit": config["auto_recruit"],
        "smtp_username": config["smtp_username"],
        "smtp_password": config["smtp_password"],
        "whimsical": config["whimsical"],
    }

    heroku_app.set_multiple(**heroku_config)

    # Wait for Redis database to be ready.
    log("Waiting for Redis...")
    ready = False
    while not ready:
        try:
            r = redis.from_url(heroku_app.redis_url)
            r.set("foo", "bar")
            ready = True
        except (ValueError, redis.exceptions.ConnectionError):
            time.sleep(2)

    log("Saving the URL of the postgres database...")
    # Set the notification URL and database URL in the config file.
    config.extend(
        {
            "notification_url": heroku_app.url + "/notifications",
            "database_url": heroku_app.db_url,
        }
    )
    config.write()
    git.add("config.txt")
    time.sleep(0.25)
    git.commit("Save URLs for database and notifications")
    time.sleep(0.25)

    # Launch the Heroku app.
    log("Pushing code to Heroku...")
    git.push(remote="heroku", branch="HEAD:master")

    log("Scaling up the dynos...")
    size = config.get("dyno_type")
    for process in ["web", "worker"]:
        qty = config.get("num_dynos_" + process)
        heroku_app.scale_up_dyno(process, qty, size)
    if config.get("clock_on"):
        heroku_app.scale_up_dyno("clock", 1, size)

    time.sleep(8)

    # Launch the experiment.
    log("Launching the experiment on the remote server and starting recruitment...")
    launch_data = _handle_launch_data("{}/launch".format(heroku_app.url), error=log)
    result = {
        "app_name": heroku_app.name,
        "app_home": heroku_app.url,
        "recruitment_msg": launch_data.get("recruitment_msg", None),
    }
    log("Experiment details:")
    log("App home: {}".format(result["app_home"]), chevrons=False)
    log("Recruiter info:")
    log(result["recruitment_msg"], chevrons=False)

    # Return to the branch whence we came.
    os.chdir(cwd)

    log("Completed deployment of experiment " + id + ".")
    return result
134606
def backup(self, filename='backup.zip', attachments=False):
        """"""
        if self.deploymentType == 'Cloud':
            url = self._options['server'] + '/rest/backup/1/export/runbackup'
            payload = json.dumps({"cbAttachments": attachments})
            self._options['headers']['X-Requested-With'] = 'XMLHttpRequest'
        else:
            url = self._options['server'] + '/secure/admin/XmlBackup.jspa'
            payload = {'filename': filename}
        try:
            r = self._session.post(url, headers=self._options['headers'], data=payload)
            if r.status_code == 200:
                return True
            else:
                logging.warning(
                    'Got %s response from calling backup.' % r.status_code)
                return r.status_code
        except Exception as e:
            logging.error("I see %s", e)
271640
private void setupOutputStream() {
    synchronized (failureLogFile) {
      // Setup is done by some thread
      if (hasSetupOutputStream) {
        return;
      }

      try {
        boolean append = false;
        if (fs.exists(failureLogFile)) {
          log.info("Failure log file %s already exists, appending to it", failureLogFile);
          append = true;
        }
        OutputStream outputStream = append ? fs.append(failureLogFile) : fs.create(failureLogFile);
        output = this.closer.register(new PrintStream(outputStream, false, Charsets.UTF_8.toString()));
      } catch (IOException e) {
        throw new RuntimeException(e);
      } finally {
        hasSetupOutputStream = true;
      }
    }
  }
437113
def setup_logging():
    """"""
    config = json.load(open(os.path.join(config_path, 'logging.json')))

    # If syslogging is disabled, set the pipeline handler to NullHandler
    if dbconfig.get('enable_syslog_forwarding', NS_LOG, False):
        try:
            config['formatters']['syslog'] = {
                'format': _get_syslog_format('cloud-inquisitor-logs')
            }

            config['handlers']['syslog'] = {
                'class': 'cloud_inquisitor.log.SyslogPipelineHandler',
                'formatter': 'syslog',
                'filters': ['standard']
            }

            config['loggers']['cloud_inquisitor']['handlers'].append('syslog')

            # Configure the audit log handler
            audit_handler = SyslogPipelineHandler()
            audit_handler.setFormatter(logging.Formatter(_get_syslog_format('cloud-inquisitor-audit')))
            audit_handler.setLevel(logging.DEBUG)

            _AUDIT_LOGGER.addHandler(audit_handler)
            _AUDIT_LOGGER.propagate = False
        except Exception as ex:
            print('An error occured while configuring the syslogger: {}'.format(ex))

    logging.config.dictConfig(config)
1305681
def setup_logging(logging_config, debug=False):
    """"""

    if logging_config is not None:
        logging.config.fileConfig(logging_config)

    else:
        logging.basicConfig(level=debug and logging.DEBUG or logging.ERROR)