Mercurial > hg > orthanc-stone
annotate Platforms/Wasm/logger.ts @ 810:7608e8107aa1
merge
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 28 May 2019 18:09:48 +0200 |
parents | 4eccf698e52f |
children | 67d0a8da4afe |
rev | line source |
---|---|
653
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
1 export enum LogSource { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
2 Cpp, |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
3 Typescript |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
4 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
5 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
6 export class StandardConsoleLogger { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
7 public showSource: boolean = true; |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
8 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
9 public debug(...args: any[]): void { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
10 this._debug(LogSource.Typescript, ...args); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
11 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
12 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
13 public debugFromCpp(...args: any[]): void { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
14 this._debug(LogSource.Cpp, ...args); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
15 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
16 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
17 public info(...args: any[]): void { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
18 this._info(LogSource.Typescript, ...args); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
19 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
20 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
21 public infoFromCpp(message: string): void { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
22 this._info(LogSource.Cpp, message); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
23 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
24 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
25 public warning(...args: any[]): void { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
26 this._warning(LogSource.Typescript, ...args); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
27 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
28 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
29 public warningFromCpp(message: string): void { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
30 this._warning(LogSource.Cpp, message); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
31 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
32 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
33 public error(...args: any[]): void { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
34 this._error(LogSource.Typescript, ...args); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
35 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
36 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
37 public errorFromCpp(message: string): void { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
38 this._error(LogSource.Cpp, message); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
39 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
40 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
41 public _debug(source: LogSource, ...args: any[]): void { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
42 if ((<any> window).IsTraceLevelEnabled) |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
43 { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
44 if ((<any> window).IsTraceLevelEnabled()) |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
45 { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
46 var output = this.getOutput(source, args); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
47 console.debug(...output); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
48 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
49 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
50 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
51 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
52 private _info(source: LogSource, ...args: any[]): void { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
53 if ((<any> window).IsInfoLevelEnabled) |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
54 { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
55 if ((<any> window).IsInfoLevelEnabled()) |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
56 { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
57 var output = this.getOutput(source, args); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
58 console.info(...output); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
59 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
60 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
61 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
62 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
63 public _warning(source: LogSource, ...args: any[]): void { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
64 var output = this.getOutput(source, args); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
65 console.warn(...output); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
66 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
67 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
68 public _error(source: LogSource, ...args: any[]): void { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
69 var output = this.getOutput(source, args); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
70 console.error(...output); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
71 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
72 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
73 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
74 private getOutput(source: LogSource, args: any[]): any[] { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
75 var prefix = this.getPrefix(); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
76 var prefixAndSource = []; |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
77 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
78 if (prefix != null) { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
79 prefixAndSource = [prefix]; |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
80 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
81 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
82 if (this.showSource) { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
83 if (source == LogSource.Typescript) { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
84 prefixAndSource = [...prefixAndSource, "TS "]; |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
85 } else if (source == LogSource.Cpp) { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
86 prefixAndSource = [...prefixAndSource, "C++"]; |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
87 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
88 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
89 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
90 if (prefixAndSource.length > 0) { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
91 prefixAndSource = [...prefixAndSource, "|"]; |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
92 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
93 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
94 return [...prefixAndSource, ...args]; |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
95 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
96 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
97 protected getPrefix(): string { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
98 return null; |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
99 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
100 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
101 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
102 export class TimeConsoleLogger extends StandardConsoleLogger { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
103 protected getPrefix(): string { |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
104 let now = new Date(); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
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"); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
106 return timeString; |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
107 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
108 } |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
109 |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
110 export var defaultLogger: StandardConsoleLogger = new TimeConsoleLogger(); |
4eccf698e52f
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
603
diff
changeset
|
111 |