Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/logger.ts @ 616:97926984d5d0
WebAssembly sample using Scene2D
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 02 May 2019 13:27:41 +0200 |
parents | 70992b38aa8a |
children | 4eccf698e52f |
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 |
603
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
13 public debugFromCpp(...args: any[]): void { |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
14 this._debug(LogSource.Cpp, ...args); |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
15 } |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
16 |
526
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
17 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
|
18 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
|
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 infoFromCpp(message: string): void { |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
22 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
|
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 warning(...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._warning(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 |
603
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
29 public warningFromCpp(message: string): void { |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
30 this._warning(LogSource.Cpp, message); |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
31 } |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
32 |
526
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
33 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
|
34 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
|
35 } |
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 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
|
38 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
|
39 } |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
40 |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
41 public _debug(source: LogSource, ...args: any[]): void { |
603
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
42 if ((<any> window).IsTraceLevelEnabled) |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
43 { |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
44 if ((<any> window).IsTraceLevelEnabled()) |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
45 { |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
46 var output = this.getOutput(source, args); |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
47 console.debug(...output); |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
48 } |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
49 } |
526
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
50 } |
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 private _info(source: LogSource, ...args: any[]): void { |
603
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
53 if ((<any> window).IsInfoLevelEnabled) |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
54 { |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
55 if ((<any> window).IsInfoLevelEnabled()) |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
56 { |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
57 var output = this.getOutput(source, args); |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
58 console.info(...output); |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
59 } |
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
60 } |
526
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 |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
63 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
|
64 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
|
65 console.warn(...output); |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
66 } |
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 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
|
69 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
|
70 console.error(...output); |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
71 } |
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 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
|
75 var prefix = this.getPrefix(); |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
76 var prefixAndSource = []; |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
77 |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
78 if (prefix != null) { |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
79 prefixAndSource = [prefix]; |
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 if (this.showSource) { |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
83 if (source == LogSource.Typescript) { |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
84 prefixAndSource = [...prefixAndSource, "TS "]; |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
85 } 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
|
86 prefixAndSource = [...prefixAndSource, "C++"]; |
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 if (prefixAndSource.length > 0) { |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
91 prefixAndSource = [...prefixAndSource, "|"]; |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
92 } |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
93 |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
94 return [...prefixAndSource, ...args]; |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
95 } |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
96 |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
97 protected getPrefix(): string { |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
98 return null; |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
99 } |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
100 } |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
101 |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
102 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
|
103 protected getPrefix(): string { |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
104 let now = new Date(); |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
105 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
|
106 return timeString; |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
107 } |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
108 } |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
109 |
548eed46f535
introduced a Logger class that displays timing and source (C++/JS)
Alain Mazy <alain@mazy.be>
parents:
diff
changeset
|
110 export var defaultLogger: StandardConsoleLogger = new TimeConsoleLogger(); |
603
70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents:
526
diff
changeset
|
111 |