Skip to content

Commit

Permalink
feat(SwingSet): allow slogSender to process all slog messages
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Feb 7, 2022
1 parent 2583ce0 commit ca4b5bc
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions packages/SwingSet/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export function makeStartXSnap(bundles, { snapStore, env, spawn }) {
* debugPrefix?: string,
* slogCallbacks?: unknown,
* slogFile?: string,
* slogSender?: (obj: any) => void,
* testTrackDecref?: unknown,
* warehousePolicy?: { maxVatsOnline?: number },
* overrideVatManagerOptions?: { consensusMode?: boolean },
Expand All @@ -145,6 +146,7 @@ export async function makeSwingsetController(
debugPrefix = '',
slogCallbacks,
slogFile,
slogSender,
spawn = ambientSpawn,
warehousePolicy = {},
overrideVatManagerOptions = {},
Expand All @@ -157,12 +159,23 @@ export async function makeSwingsetController(
slogFile && (await fs.createWriteStream(slogFile, { flags: 'a' })); // append

function writeSlogObject(obj) {
// TODO sqlite
if (!slogSender && !slogF) {
// Fast path; nothing to do.
return;
}

// Add a timestamp to the slog input object.
const timeMS = performance.timeOrigin + performance.now();
const time = timeMS / 1000;
const timedObj = { time, ...obj };

if (slogSender) {
// Allow the SwingSet host to do anything they want with slog messages.
slogSender(timedObj);
}
if (slogF) {
const timeMS = performance.timeOrigin + performance.now();
const time = timeMS / 1000;
slogF.write(
JSON.stringify({ time, ...obj }, (_, arg) =>
JSON.stringify(timedObj, (_, arg) =>
typeof arg === 'bigint' ? Number(arg) : arg,
),
);
Expand Down

0 comments on commit ca4b5bc

Please sign in to comment.