Skip to content

Commit

Permalink
feat: silence the vat logs for ag-chain-cosmos
Browse files Browse the repository at this point in the history
This helps quell the anxiety that validators get when bizarre
application errors happen.  They still appear when running locally
or an ag-solo, but not on-chain.

To reenable, use:
`DEBUG=SwingSet:vat,SwingSet:ls ag-chain-cosmos start`
  • Loading branch information
michaelfig committed Mar 16, 2021
1 parent 9eec3e3 commit 16cf2bb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
8 changes: 4 additions & 4 deletions packages/cosmic-swingset/lib/ag-solo/fake-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { makeWithQueue } from './vats/queue';
import { makeBatchedDeliver } from './batched-deliver';
import { getMeterProvider } from '../kernel-stats';

const log = anylogger('fake-chain');
const console = anylogger('fake-chain');

const PRETEND_BLOCK_DELAY = 5;
const scaleBlockTime = ms => Math.floor(ms / 1000);
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
assert(!replay, X`Replay not implemented`);
}

const meterProvider = getMeterProvider(log, process.env);
const meterProvider = getMeterProvider(console, process.env);
const s = await launch(
stateDBdir,
mailboxStorage,
Expand Down Expand Up @@ -133,7 +133,7 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
thisBlock = [];
blockTime += scaleBlockTime(Date.now() - actualStart);
} catch (e) {
log.error(`error fake processing`, e);
console.error(`error fake processing`, e);
}

clearTimeout(nextBlockTimeout);
Expand All @@ -148,7 +148,7 @@ export async function connectToFakeChain(basedir, GCI, delay, inbound) {
let totalDeliveries = 0;
async function deliver(newMessages, acknum) {
totalDeliveries += 1;
console.log(`delivering to ${GCI} (trips=${totalDeliveries})`);
console.info(`delivering to ${GCI} (trips=${totalDeliveries})`);

intoChain.push([newMessages, acknum]);
if (!delay) {
Expand Down
22 changes: 16 additions & 6 deletions packages/cosmic-swingset/lib/anylogger-agoric.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@ import anylogger from 'anylogger';
// Turn on debugging output with DEBUG=agoric

let debugging;
const filterOutPrefixes = [];
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';
if (!process.env.DEBUG.includes('SwingSet:vat')) {
filterOutPrefixes.push('SwingSet:vat:');
}
if (!process.env.DEBUG.includes('SwingSet:ls')) {
filterOutPrefixes.push('SwingSet:ls:');
}
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];

Expand All @@ -22,8 +31,9 @@ anylogger.ext = (l, o) => {
l.enabledFor = lvl => defaultLevel >= anylogger.levels[lvl];

const prefix = l.name.replace(/:/g, ': ');
const filteredOut = filterOutPrefixes.find(pfx => l.name.startsWith(pfx));
for (const [level, code] of Object.entries(anylogger.levels)) {
if (code > defaultLevel) {
if (filteredOut || code > defaultLevel) {
// Disable printing.
l[level] = () => {};
} else {
Expand Down
5 changes: 5 additions & 0 deletions packages/cosmic-swingset/lib/chain-entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const agcc = require('@agoric/cosmos');
// (dep chain: temp->glob->minimatch->brace-expansion)
esmRequire('@agoric/install-metering-and-ses');

if (!process.env.DEBUG) {
// By default, disable debugging.
process.env.DEBUG = '';
}

const path = require('path');
const os = require('os');

Expand Down

0 comments on commit 16cf2bb

Please sign in to comment.