Skip to content

Commit

Permalink
make kernel log do varargs and abbreviate long strings
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed May 31, 2019
1 parent d7d6e6c commit 9df6898
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,24 @@ export default function buildKernel(kernelEndowments, external) {
if (kernelKeeper.hasVat(vatID)) {
throw new Error(`already have a vat named '${vatID}'`);
}
function abbreviateReviver(_, arg) {
if (typeof arg === 'string' && arg.length >= 40) {
// truncate long strings
return `${arg.slice(0, 15)}...${arg.slice(arg.length - 15)}`;
}
return arg;
}
const helpers = harden({
vatID,
makeLiveSlots,
makeCommsSlots,
log(str) {
kernelKeeper.log(`${str}`);
log(...args) {
const rendered = args.map(arg =>
typeof arg === 'string'
? arg
: JSON.stringify(arg, abbreviateReviver),
);
kernelKeeper.log(rendered.join(''));
},
});

Expand Down

0 comments on commit 9df6898

Please sign in to comment.