Skip to content

Commit ff97324

Browse files
michaelfigerights
authored andcommitted
fix!: clarify the meaning of $DEBUG
1 parent 9441541 commit ff97324

File tree

7 files changed

+60
-43
lines changed

7 files changed

+60
-43
lines changed

docs/env.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ Affects: agoric (CLI), ag-chain-cosmos, ag-solo
4949

5050
Purpose: to change the meaning of `console.log` and other console methods
5151

52-
Description: uses `anylogger` to change whether the following methods (in order
53-
of increasing severity) are active for a given context:
52+
Description: uses `anylogger` to change whether the following methods are active
53+
for a given context, in order of increasing severity:
5454

5555
1. `console.debug`
5656
2. `console.log`
@@ -61,17 +61,16 @@ of increasing severity) are active for a given context:
6161
If not set, then default (`console.info` and above) logging is enabled.
6262
(`console.log` and `console.debug` logging is disabled.)
6363

64-
If set to an empty string, or running in `ag-chain-cosmos start` mode, don't
65-
print any logs. This is part of "consensus mode."
66-
6764
Otherwise, set to a comma-separated list of strings.
6865

6966
If one of those strings is
70-
- `agoric`, then print all console messages for the entire `agoric-sdk``.
67+
- `agoric:${level}`, then don't print `agoric-sdk` console messages below `${level}`.
68+
- `agoric:none`, then silence all `agoric-sdk` console messages.
69+
- `agoric` (an alias for `agoric:debug`) print all `agoric-sdk` console messages.
7170
- `track-turns`, then log errors at the top of the event-loop that may otherwise be unreported. See also the TRACK_TURNS environment variable below.
7271
- `label-instances`, then log exo instances with a unique label per instance. HAZARD This causes an information leak in the messages of thrown errors, which are available even to code without access to the console. Use with care.
7372

74-
For each of those strings begins with a prefix recognized as indicating what
73+
For each of those strings beginning with a prefix recognized as indicating what
7574
console messages to enable, pass it to `makeConsole`. For example:
7675

7776
- `DEBUG=SwingSet:ls` enable all console messages for liveslots, regardless of vat.

packages/agoric-cli/src/anylogger-agoric.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@ import { getEnvironmentOptionsList } from '@endo/env-options';
22
import anylogger from 'anylogger';
33
import chalk from 'chalk';
44

5-
// Turn on debugging output with DEBUG=agoric
5+
// Turn on debugging output with DEBUG=agoric or DEBUG=agoric:${level}
66

77
const DEBUG_LIST = getEnvironmentOptionsList('DEBUG');
88

99
let selectedLevel = 'info';
10-
if (DEBUG_LIST.length === 0) {
11-
selectedLevel = 'log';
12-
} else if (DEBUG_LIST.includes('agoric')) {
13-
selectedLevel = 'debug';
10+
for (const level of DEBUG_LIST) {
11+
const parts = level.split(':');
12+
if (parts[0] !== 'agoric') {
13+
continue;
14+
}
15+
if (parts.length > 1) {
16+
selectedLevel = parts[1];
17+
} else {
18+
selectedLevel = 'debug';
19+
}
1420
}
1521
const defaultLevel = anylogger.levels[selectedLevel];
1622

packages/agoric-cli/src/cosmos.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export default async function cosmosMain(progname, rawArgs, powers, opts) {
1414
const pspawnEnv = { ...process.env };
1515
if (popts.verbose > 1) {
1616
// Enable verbose logs.
17-
pspawnEnv.DEBUG = 'agoric';
17+
pspawnEnv.DEBUG = 'agoric:info';
1818
} else if (!popts.verbose) {
1919
// Disable more logs.
20-
pspawnEnv.DEBUG = '';
20+
pspawnEnv.DEBUG = 'agoric:none';
2121
}
2222

2323
const pspawn = makePspawn({ env: pspawnEnv, log, spawn, chalk });

packages/agoric-cli/src/start.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ export default async function startMain(progname, rawArgs, powers, opts) {
7171
const pspawnEnv = { ...process.env };
7272
if (opts.verbose > 1) {
7373
// Loudly verbose logs (nondeterministic).
74-
pspawnEnv.DEBUG = 'agoric,SwingSet:vat,SwingSet:ls';
74+
pspawnEnv.DEBUG = 'agoric:debug,SwingSet:vat,SwingSet:ls';
7575
} else if (opts.verbose) {
7676
// Verbose vat logs (nondeterministic).
77-
pspawnEnv.DEBUG = 'SwingSet:vat,SwingSet:ls';
77+
pspawnEnv.DEBUG = 'agoric:info,SwingSet:vat,SwingSet:ls';
7878
}
7979

8080
const pspawn = makePspawn({ env: pspawnEnv, spawn, log, chalk });

packages/agoric-cli/tools/getting-started.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const gettingStartedWorkflowTest = async (t, options = {}) => {
6464
// console.error('running agoric-cli', ...extraArgs, ...args);
6565
return pspawnStdout(agoricCmd[0], [...agoricCmd.slice(1), ...args], {
6666
stdio: ['ignore', 'pipe', 'inherit'],
67-
env: { ...process.env, DEBUG: 'agoric' },
67+
env: { ...process.env, DEBUG: 'agoric:debug' },
6868
detached: true,
6969
...opts,
7070
});

packages/cosmic-swingset/src/anylogger-agoric.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,48 @@ import anylogger from 'anylogger';
44
// Turn on debugging output with DEBUG=agoric
55

66
const DEBUG_LIST = getEnvironmentOptionsList('DEBUG');
7-
let debugging;
87

9-
const filterOutPrefixes = [];
10-
// Mute vat logging unless requested, for determinism.
11-
if (!DEBUG_LIST.includes('SwingSet:vat')) {
12-
filterOutPrefixes.push('SwingSet:vat:');
13-
}
14-
// Mute liveSlots logging unless requested, for determinism.
15-
if (!DEBUG_LIST.includes('SwingSet:ls')) {
16-
filterOutPrefixes.push('SwingSet:ls:');
17-
}
8+
const isVatLogNameColon = nameColon =>
9+
['SwingSet:ls:', 'SwingSet:vat:'].some(sel => nameColon.startsWith(sel));
10+
11+
// Turn on debugging output with DEBUG=agoric or DEBUG=agoric:${level}
1812

19-
if (DEBUG_LIST.length === 0) {
20-
// DEBUG wasn't set, default to info level; quieter than normal.
21-
debugging = 'info';
22-
} else if (DEBUG_LIST.includes('agoric')) {
23-
// $DEBUG set and we're enabled; loudly verbose.
24-
debugging = 'debug';
25-
} else {
26-
// $DEBUG set but we're not enabled; slightly louder than normal.
27-
debugging = 'log';
13+
let selectedLevel = 'info';
14+
for (const selector of DEBUG_LIST) {
15+
const parts = selector.split(':');
16+
if (parts[0] !== 'agoric') {
17+
continue;
18+
}
19+
if (parts.length > 1) {
20+
selectedLevel = parts[1];
21+
} else {
22+
selectedLevel = 'debug';
23+
}
2824
}
29-
const defaultLevel = anylogger.levels[debugging];
25+
const defaultLevel = anylogger.levels[selectedLevel];
3026

3127
const oldExt = anylogger.ext;
3228
anylogger.ext = (l, o) => {
3329
l = oldExt(l, o);
3430
l.enabledFor = lvl => defaultLevel >= anylogger.levels[lvl];
3531

3632
const prefix = l.name.replace(/:/g, ': ');
37-
const filteredOut = filterOutPrefixes.find(pfx => l.name.startsWith(pfx));
33+
34+
const nameColon = `${l.name}:`;
35+
const logBelongsToVat = isVatLogNameColon(nameColon);
36+
37+
const logMatchesSelector = DEBUG_LIST.some(selector => {
38+
const selectorColon = `${selector}:`;
39+
if (!logBelongsToVat) {
40+
return true;
41+
}
42+
43+
// If this is a vat log, then it is enabled if it matches the selector.
44+
return nameColon.startsWith(selectorColon);
45+
});
46+
3847
for (const [level, code] of Object.entries(anylogger.levels)) {
39-
if (filteredOut || code > defaultLevel) {
48+
if (!logMatchesSelector || code > defaultLevel) {
4049
// Disable printing.
4150
l[level] = () => {};
4251
} else {

packages/solo/src/start.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,15 @@ const deployWallet = async ({ agWallet, deploys, hostport }) => {
371371

372372
// Use the same verbosity as our caller did for us.
373373
let verbosity;
374-
if (process.env.DEBUG === undefined || process.env.DEBUG === '') {
375-
verbosity = [];
376-
} else if (process.env.DEBUG.split(',').includes('agoric')) {
374+
const DEBUG_LIST = (process.env.DEBUG || '').split(',');
375+
if (
376+
DEBUG_LIST.find(selector => ['agoric:debug', 'agoric'].includes(selector))
377+
) {
377378
verbosity = ['-vv'];
378-
} else {
379+
} else if (DEBUG_LIST.includes('agoric:info')) {
379380
verbosity = ['-v'];
381+
} else {
382+
verbosity = [];
380383
}
381384

382385
// Launch the agoric wallet deploys (if any). The assumption is that the CLI

0 commit comments

Comments
 (0)