-
Notifications
You must be signed in to change notification settings - Fork 1
/
spy.ts
76 lines (69 loc) · 1.29 KB
/
spy.ts
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { SizeRestrictedLog } from '../util';
import { Entries } from './base_module';
import { SpyHttp } from './spy_http';
/**
* Main class which handle the spy operations
*
* @export
* @class Spy
*/
export class Spy {
/**
* Creates an instance of Spy.
* @param {number} logSize
* @memberof Spy
*/
constructor(readonly logSize: number) {
SpyHttp.init(SizeRestrictedLog.getInstance(logSize));
}
/**
* Get an instance of spy
*
* @static
* @param {number} [logSize=10]
* @returns
* @memberof Spy
*/
static getInstance(logSize = 10) {
return new Spy(logSize);
}
/**
* Execute start() in each spy module
*
* @memberof Spy
*/
start() {
SpyHttp.start();
}
/**
* Execute stop() in each spy module
*
* @memberof Spy
*/
stop() {
SpyHttp.stop();
}
/**
* Print the formated logs from each spy
*
* @returns {string}
* @memberof Spy
*/
printEntries(): string {
const op = [];
const entriesSpyHttp = SpyHttp.getEntries();
op.push(this.buildPrintOutput(entriesSpyHttp));
return `
******************
Spied module logs:
******************
${op.join('')}`;
}
private buildPrintOutput(entries: Entries) {
return `
${entries.module}
${entries.remark}
${entries.log.toString()}
`;
}
}