Skip to content

Commit

Permalink
fix: allow disabling of logging by setting DEBUG=''
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Mar 19, 2020
1 parent 258e4c9 commit 131c1c6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
19 changes: 16 additions & 3 deletions packages/agoric-cli/lib/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ export default async function startMain(progname, rawArgs, powers, opts) {
const { anylogger, fs, spawn, os, process } = powers;
const log = anylogger('agoric:start');

const pspawn = (cmd, cargs, { stdio = 'inherit', ...rest } = {}) => {
const pspawnEnv = { ...process.env };
const pspawn = (
cmd,
cargs,
{ stdio = 'inherit', env = pspawnEnv, ...rest } = {},
) => {
log.info(chalk.blueBright(cmd, ...cargs));
const cp = spawn(cmd, cargs, { stdio, ...rest });
const cp = spawn(cmd, cargs, { stdio, env, ...rest });
const pr = new Promise((resolve, _reject) => {
cp.on('exit', resolve);
cp.on('error', () => resolve(-1));
Expand Down Expand Up @@ -62,6 +67,7 @@ export default async function startMain(progname, rawArgs, powers, opts) {
async function startFakeChain(profileName, _startArgs, popts) {
const fakeDelay =
popts.delay === undefined ? FAKE_CHAIN_DELAY : Number(popts.delay);

if (!opts.sdk) {
if (!(await exists('_agstate/agoric-servers/node_modules'))) {
log.error(`you must first run '${progname} install'`);
Expand Down Expand Up @@ -195,10 +201,17 @@ export default async function startMain(progname, rawArgs, powers, opts) {
};

const { _: args, ...popts } = parseArgs(rawArgs, {
boolean: ['reset', 'restart', 'pull'],
boolean: ['reset', 'restart', 'pull', 'debug'],
default: { restart: true },
});

if (popts.debug) {
// Crank out the debugging.
pspawnEnv.DEBUG = 'agoric';
} else {
pspawnEnv.DEBUG = '';
}

const profileName = args[0] || 'dev';
const startFn = profiles[profileName];
if (!startFn) {
Expand Down
14 changes: 12 additions & 2 deletions packages/cosmic-swingset/lib/anylogger-agoric.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ import anylogger from 'anylogger';

// Turn on debugging output with DEBUG=agoric

const debugging = process.env.DEBUG && process.env.DEBUG.includes('agoric');
const defaultLevel = debugging ? anylogger.levels.debug : anylogger.levels.log;
let debugging;
if (process.env.DEBUG === undefined) {
// DEBUG not set, default to log level.
debugging = 'log';
} else if (process.env.DEBUG.includes('agoric')) {
// DEBUG set and we're enabled; verbose.
debugging = 'debug';
} else {
// DEBUG set but we're not enabled; quieter than normal.
debugging = 'info';
}
const defaultLevel = anylogger.levels[debugging];

const oldExt = anylogger.ext;
anylogger.ext = (l, o) => {
Expand Down

0 comments on commit 131c1c6

Please sign in to comment.