File size: 452 Bytes
d605f27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

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])};
	}
};