annotate Platforms/Wasm/logger.ts @ 526:548eed46f535 dev

introduced a Logger class that displays timing and source (C++/JS)
author Alain Mazy <alain@mazy.be>
date Thu, 14 Mar 2019 19:04:35 +0100
parents
children 70992b38aa8a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
526
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
1 export enum LogSource {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
2 Cpp,
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
3 Typescript
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
4 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
5
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
6 export class StandardConsoleLogger {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
7 public showSource: boolean = true;
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
8
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
9 public debug(...args: any[]): void {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
10 this._debug(LogSource.Typescript, ...args);
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
11 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
12
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
13 public info(...args: any[]): void {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
14 this._info(LogSource.Typescript, ...args);
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
15 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
16
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
17 public infoFromCpp(message: string): void {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
18 this._info(LogSource.Cpp, message);
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
19 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
20
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
21 public warning(...args: any[]): void {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
22 this._warning(LogSource.Typescript, ...args);
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
23 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
24
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
25 public error(...args: any[]): void {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
26 this._error(LogSource.Typescript, ...args);
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
27 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
28
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
29 public errorFromCpp(message: string): void {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
30 this._error(LogSource.Cpp, message);
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
31 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
32
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
33 public _debug(source: LogSource, ...args: any[]): void {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
34 var output = this.getOutput(source, args);
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
35 console.debug(...output);
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
36 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
37
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
38 private _info(source: LogSource, ...args: any[]): void {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
39 var output = this.getOutput(source, args);
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
40 console.info(...output);
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
41 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
42
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
43 public _warning(source: LogSource, ...args: any[]): void {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
44 var output = this.getOutput(source, args);
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
45 console.warn(...output);
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
46 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
47
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
48 public _error(source: LogSource, ...args: any[]): void {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
49 var output = this.getOutput(source, args);
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
50 console.error(...output);
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
51 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
52
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
53
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
54 private getOutput(source: LogSource, args: any[]): any[] {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
55 var prefix = this.getPrefix();
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
56 var prefixAndSource = [];
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
57
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
58 if (prefix != null) {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
59 prefixAndSource = [prefix];
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
60 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
61
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
62 if (this.showSource) {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
63 if (source == LogSource.Typescript) {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
64 prefixAndSource = [...prefixAndSource, "TS "];
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
65 } else if (source == LogSource.Cpp) {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
66 prefixAndSource = [...prefixAndSource, "C++"];
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
67 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
68 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
69
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
70 if (prefixAndSource.length > 0) {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
71 prefixAndSource = [...prefixAndSource, "|"];
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
72 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
73
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
74 return [...prefixAndSource, ...args];
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
75 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
76
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
77 protected getPrefix(): string {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
78 return null;
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
79 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
80 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
81
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
82 export class TimeConsoleLogger extends StandardConsoleLogger {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
83 protected getPrefix(): string {
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
84 let now = new Date();
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
85 let timeString = now.getHours().toString().padStart(2, "0") + ":" + now.getMinutes().toString().padStart(2, "0") + ":" + now.getSeconds().toString().padStart(2, "0") + "." + now.getMilliseconds().toString().padStart(3, "0");
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
86 return timeString;
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
87 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
88 }
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
89
548eed46f535 introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff changeset
90 export var defaultLogger: StandardConsoleLogger = new TimeConsoleLogger();