lotus / inc /logRecorder.ts
k-l-lambda's picture
commit lotus dist.
d605f27
raw
history blame
452 Bytes
interface Record {
desc: string;
data: any;
};
export default class LogRecorder {
enabled: boolean;
records: Record[];
constructor ({enabled = false} = {}) {
this.enabled = enabled;
this.records = [];
}
append (desc: string, data?: any) {
if (this.enabled)
this.records.push({desc, data});
}
toJSON () {
if (!this.enabled)
return null;
return {records: this.records.map(record => [record.desc, record.data])};
}
};