Skip to content

Commit 1284f64

Browse files
committed
fix: DEBUG harmony
1 parent cbec0c6 commit 1284f64

File tree

9 files changed

+45
-37
lines changed

9 files changed

+45
-37
lines changed

docs/env.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ If not set, then default (`console.info` and above) logging is enabled.
6464
If set to an empty string, or running in `ag-chain-cosmos start` mode, don't
6565
print any logs. This is part of "consensus mode."
6666

67-
If set to a value that contains the substring `agoric`, then print all console
68-
messages for the entire SDK.
67+
Otherwise, set to a comma-separated list of strings.
6968

70-
Otherwise, set to a comma-separated list of prefixes, where each prefix is the
71-
context given to `makeConsole`. For example:
69+
If one of those strings is
70+
- `agoric`, then print all console messages for the entire `agoric-sdk``.
71+
- `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.
72+
- `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.
73+
74+
For each of those strings begins with a prefix recognized as indicating what
75+
console messages to enable, pass it to `makeConsole`. For example:
7276

7377
- `DEBUG=SwingSet:ls` enable all console messages for liveslots, regardless of vat.
7478
- `DEBUG=SwingSet:ls:v13` enable for liveslots in vat 13.
@@ -97,6 +101,10 @@ Description: When nonempty, create pretend prepopulated tokens like "moola" and
97101

98102
Lifetime: until chain is mature enough not to need any pretend tokens
99103

104+
## LOCKDOWN_*
105+
106+
For the envoronment variables beginning with `LOCKDOWN_` , see [`lockdown` Options](https://github.com/endojs/endo/blob/master/packages/ses/docs/lockdown.md).
107+
100108
## OTEL_EXPORTER_PROMETHEUS_PORT
101109

102110
Affects: cosmic-swingset
@@ -238,3 +246,8 @@ records individually. `config.defaultManagerType` has a higher priority so that
238246
tests which require a specific worker (e.g. which exercise XS heap snapshots,
239247
or metering) can override the env var, so they won't break under `yarn
240248
test:xs`.
249+
250+
## TRACK_TURNS
251+
252+
Log the deep causality stack behind logged errors if possible. See also the
253+
`DEBUG` setting `DEBUG=track-turns` above.

packages/agoric-cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@endo/bundle-source": "^2.5.2",
5959
"@endo/captp": "^3.1.2",
6060
"@endo/compartment-mapper": "^0.8.5",
61+
"@endo/env-options": "^0.1.1",
6162
"@endo/far": "^0.2.19",
6263
"@endo/init": "^0.5.57",
6364
"@endo/marshal": "^0.8.6",

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
/* global process */
1+
import { getEnvironmentOptionsList } from '@endo/env-options';
22
import anylogger from 'anylogger';
33
import chalk from 'chalk';
44

55
// Turn on debugging output with DEBUG=agoric
6-
const { DEBUG } = process.env;
6+
7+
const DEBUG_LIST = getEnvironmentOptionsList('DEBUG');
8+
79
let selectedLevel = 'info';
8-
if (DEBUG === undefined) {
10+
if (DEBUG_LIST.length === 0) {
911
selectedLevel = 'log';
10-
} else if (DEBUG.includes('agoric')) {
12+
} else if (DEBUG_LIST.includes('agoric')) {
1113
selectedLevel = 'debug';
1214
}
1315
const defaultLevel = anylogger.levels[selectedLevel];

packages/cosmic-swingset/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"@agoric/swingset-vat": "^0.32.2",
3232
"@agoric/telemetry": "^0.6.2",
3333
"@agoric/vm-config": "^0.1.0",
34+
"@endo/env-options": "^0.1.1",
3435
"@endo/far": "^0.2.19",
3536
"@endo/import-bundle": "^0.3.5",
3637
"@endo/init": "^0.5.57",

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
/* global process */
1+
import { getEnvironmentOptionsList } from '@endo/env-options';
22
import anylogger from 'anylogger';
33

44
// Turn on debugging output with DEBUG=agoric
55

6-
const { DEBUG: debugEnv = '' } = process.env;
6+
const DEBUG_LIST = getEnvironmentOptionsList('DEBUG');
77
let debugging;
88

99
const filterOutPrefixes = [];
1010
// Mute vat logging unless requested, for determinism.
11-
if (!debugEnv.includes('SwingSet:vat')) {
11+
if (!DEBUG_LIST.includes('SwingSet:vat')) {
1212
filterOutPrefixes.push('SwingSet:vat:');
1313
}
1414
// Mute liveSlots logging unless requested, for determinism.
15-
if (!debugEnv.includes('SwingSet:ls')) {
15+
if (!DEBUG_LIST.includes('SwingSet:ls')) {
1616
filterOutPrefixes.push('SwingSet:ls:');
1717
}
1818

19-
if (process.env.DEBUG === undefined) {
19+
if (DEBUG_LIST.length === 0) {
2020
// DEBUG wasn't set, default to info level; quieter than normal.
2121
debugging = 'info';
22-
} else if (debugEnv.includes('agoric')) {
22+
} else if (DEBUG_LIST.includes('agoric')) {
2323
// $DEBUG set and we're enabled; loudly verbose.
2424
debugging = 'debug';
2525
} else {

packages/smart-wallet/test/test-addAsset.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test.before(async t => {
3737
t.context = await makeDefaultTestContext(t, withBankManager);
3838
});
3939

40-
const DEBUG = false;
40+
const LOG_NEWS_HEAD = false;
4141
const bigIntReplacer = (_key, val) =>
4242
typeof val === 'bigint' ? Number(val) : val;
4343

@@ -67,7 +67,7 @@ test.serial('avoid O(wallets) storage writes for a new asset', async t => {
6767
const news = await E(current).subscribeAfter(publishCount);
6868
publishCount = news.publishCount;
6969
chainStorageWrites += 1;
70-
if (DEBUG) {
70+
if (LOG_NEWS_HEAD) {
7171
console.log(JSON.stringify(news.head, bigIntReplacer, 2));
7272
}
7373
}

packages/solo/src/start.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,9 @@ 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) {
374+
if (process.env.DEBUG === undefined || process.env.DEBUG === '') {
375375
verbosity = [];
376-
} else if (process.env.DEBUG.includes('agoric')) {
376+
} else if (process.env.DEBUG.split(',').includes('agoric')) {
377377
verbosity = ['-vv'];
378378
} else {
379379
verbosity = ['-v'];

packages/swingset-liveslots/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@agoric/assert": "^0.6.0",
2121
"@agoric/internal": "^0.3.2",
2222
"@agoric/store": "^0.9.2",
23+
"@endo/env-options": "^0.1.1",
2324
"@endo/eventual-send": "^0.17.3",
2425
"@endo/exo": "^0.2.3",
2526
"@endo/far": "^0.2.19",

packages/swingset-liveslots/src/virtualObjectManager.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* global globalThis */
22
/* eslint-disable no-use-before-define, jsdoc/require-returns-type */
33

4+
import { environmentOptionsListHas } from '@endo/env-options';
45
import { assert, Fail } from '@agoric/assert';
56
import { assertPattern, mustMatch } from '@agoric/store';
67
import { defendPrototype, defendPrototypeKit } from '@endo/exo/tools.js';
@@ -14,26 +15,17 @@ import {
1415
checkAndUpdateFacetiousness,
1516
} from './facetiousness.js';
1617

18+
// TODO Why is this here but commented out? If no longer relevant, remove
19+
// import { kdebug } from './kdebug.js';
20+
1721
/** @template T @typedef {import('@agoric/vat-data').DefineKindOptions<T>} DefineKindOptions */
1822

1923
const { hasOwn, defineProperty, getOwnPropertyNames, entries } = Object;
2024
const { ownKeys } = Reflect;
21-
const { quote: q } = assert;
22-
23-
// See https://github.com/Agoric/agoric-sdk/issues/8005
24-
// Once agoric-sdk is upgraded to depend on endo post
25-
// https://github.com/endojs/endo/pull/1606 then remove this
26-
// definition of `b` and say instead
27-
// ```js
28-
// const { quote: q, base: b } = assert;
29-
// ```
30-
const b = index => q(Number(index));
31-
32-
// import { kdebug } from './kdebug.js';
33-
34-
// TODO Use environment-options.js currently in ses/src after factoring it out
35-
// to a new package.
36-
const env = (globalThis.process || {}).env || {};
25+
// TODO https://github.com/Agoric/agoric-sdk/issues/8005
26+
// TODO https://github.com/endojs/endo/issues/1703
27+
// @ts-expect-error
28+
const { quote: q, bare: b } = assert;
3729

3830
// Turn on to give each exo instance its own toStringTag value which exposes
3931
// the SwingSet vref.
@@ -42,9 +34,7 @@ const env = (globalThis.process || {}).env || {};
4234
// confidential object-creation activity, so this must not be something
4335
// that unprivileged vat code (including unprivileged contracts) can do
4436
// for themselves.
45-
const LABEL_INSTANCES = (env.DEBUG || '')
46-
.split(':')
47-
.includes('label-instances');
37+
const LABEL_INSTANCES = environmentOptionsListHas('DEBUG', 'label-instances');
4838

4939
// This file implements the "Virtual Objects" system, currently documented in
5040
// {@link https://github.com/Agoric/agoric-sdk/blob/master/packages/SwingSet/docs/virtual-objects.md})

0 commit comments

Comments
 (0)