Skip to content

Commit

Permalink
Merge pull request Agoric#62 from Agoric/better-logging
Browse files Browse the repository at this point in the history
make kernel log do varargs and abbreviate long strings
  • Loading branch information
erights authored May 31, 2019
2 parents d7d6e6c + 9df6898 commit 701732c
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 701732c

Please sign in to comment.