| @@ -47,8 +47,7 function ActivatableMixin<TBase extends | |||||
| 47 | try { |
|
47 | try { | |
| 48 | await this.onActivated(ct); |
|
48 | await this.onActivated(ct); | |
| 49 | } catch(e) { |
|
49 | } catch(e) { | |
| 50 | log.error(e); |
|
50 | log.error("Suppressed onActivated error: {0}", e); | |
| 51 | // TODO log error |
|
|||
| 52 |
|
|
51 | } | |
| 53 | this.completeSuccess(); |
|
52 | this.completeSuccess(); | |
| 54 | } catch (e) { |
|
53 | } catch (e) { | |
| @@ -76,8 +75,8 function ActivatableMixin<TBase extends | |||||
| 76 | this._active = false; |
|
75 | this._active = false; | |
| 77 | try { |
|
76 | try { | |
| 78 | await this.onDeactivated(ct); |
|
77 | await this.onDeactivated(ct); | |
| 79 | } catch { |
|
78 | } catch(e) { | |
| 80 | // TODO log error |
|
79 | log.error("Suppressed onDeactivated error: {0}", e); | |
| 81 |
|
|
80 | } | |
| 82 | this.completeSuccess(); |
|
81 | this.completeSuccess(); | |
| 83 | } catch (e) { |
|
82 | } catch (e) { | |
| @@ -90,7 +89,7 function ActivatableMixin<TBase extends | |||||
| 90 | } |
|
89 | } | |
| 91 |
|
90 | |||
| 92 | namespace ActivatableMixin { |
|
91 | namespace ActivatableMixin { | |
| 93 |
|
92 | export const traceSource = log; | ||
| 94 | } |
|
93 | } | |
| 95 |
|
94 | |||
| 96 | export = ActivatableMixin; No newline at end of file |
|
95 | export = ActivatableMixin; | |
| @@ -133,28 +133,60 class TraceSource { | |||||
| 133 | this.emit(TraceSource.WarnLevel, format(msg, args)); |
|
133 | this.emit(TraceSource.WarnLevel, format(msg, args)); | |
| 134 | } |
|
134 | } | |
| 135 |
|
135 | |||
|
|
136 | /** | |||
|
|
137 | * returns true if errors will be recorded. | |||
|
|
138 | */ | |||
| 136 | isErrorEnabled() { |
|
139 | isErrorEnabled() { | |
| 137 | return this.level >= TraceSource.ErrorLevel; |
|
140 | return this.level >= TraceSource.ErrorLevel; | |
| 138 | } |
|
141 | } | |
| 139 |
|
142 | |||
|
|
143 | /** | |||
|
|
144 | * Traces a error. | |||
|
|
145 | * | |||
|
|
146 | * @param msg the message. | |||
|
|
147 | * @param args parameters which will be substituted in the message. | |||
|
|
148 | */ | |||
| 140 | error(msg: string, ...args: any[]) { |
|
149 | error(msg: string, ...args: any[]) { | |
| 141 | if (this.isEnabled(TraceSource.ErrorLevel)) |
|
150 | if (this.isEnabled(TraceSource.ErrorLevel)) | |
| 142 | this.emit(TraceSource.ErrorLevel, format(msg, args)); |
|
151 | this.emit(TraceSource.ErrorLevel, format(msg, args)); | |
| 143 | } |
|
152 | } | |
| 144 |
|
153 | |||
|
|
154 | /** | |||
|
|
155 | * Checks whether the specified level is enabled for this | |||
|
|
156 | * trace source. | |||
|
|
157 | * | |||
|
|
158 | * @param level the trace level which should be checked. | |||
|
|
159 | */ | |||
| 145 | isEnabled(level: number) { |
|
160 | isEnabled(level: number) { | |
| 146 | return (this.level >= level); |
|
161 | return (this.level >= level); | |
| 147 | } |
|
162 | } | |
| 148 |
|
163 | |||
|
|
164 | /** | |||
|
|
165 | * Traces a raw event, passing data as it is to the underlying listeners | |||
|
|
166 | * | |||
|
|
167 | * @param level the level of the event | |||
|
|
168 | * @param arg the data of the event, can be a simple string or any object. | |||
|
|
169 | */ | |||
| 149 | traceEvent(level: number, arg: any) { |
|
170 | traceEvent(level: number, arg: any) { | |
| 150 | if (this.isEnabled(level)) |
|
171 | if (this.isEnabled(level)) | |
| 151 | this.emit(level, arg); |
|
172 | this.emit(level, arg); | |
| 152 | } |
|
173 | } | |
| 153 |
|
174 | |||
|
|
175 | /** | |||
|
|
176 | * Register the specified handler to be called for every new and already | |||
|
|
177 | * created trace source. | |||
|
|
178 | * | |||
|
|
179 | * @param handler the handler which will be called for each trace source | |||
|
|
180 | */ | |||
| 154 | static on(handler: TraceSourceHandler) { |
|
181 | static on(handler: TraceSourceHandler) { | |
| 155 | return Registry.instance.on(handler); |
|
182 | return Registry.instance.on(handler); | |
| 156 | } |
|
183 | } | |
| 157 |
|
184 | |||
|
|
185 | /** | |||
|
|
186 | * Creates or returns already created trace source for the specified id. | |||
|
|
187 | * | |||
|
|
188 | * @param id the id for the trace source | |||
|
|
189 | */ | |||
| 158 | static get(id: any) { |
|
190 | static get(id: any) { | |
| 159 | return Registry.instance.get(id); |
|
191 | return Registry.instance.get(id); | |
| 160 | } |
|
192 | } | |
| @@ -1,1 +1,1 | |||||
| 1 | define(["./ActivatableTests", "./trace-test"]); No newline at end of file |
|
1 | define(["./ActivatableTests", "./trace-test", "./TraceSourceTests"]); No newline at end of file | |
| @@ -6,9 +6,17 const sourceId = 'test/TraceSourceTests' | |||||
| 6 | tape('', t => { |
|
6 | tape('', t => { | |
| 7 | let trace = TraceSource.get(sourceId); |
|
7 | let trace = TraceSource.get(sourceId); | |
| 8 |
|
8 | |||
| 9 | let h = trace.on((sender,level,msg) => { |
|
9 | trace.level = TraceSource.DebugLevel; | |
| 10 |
|
10 | |||
|
|
11 | let h = trace.on((sender,level,msg) => { | |||
|
|
12 | t.equal(sender, trace, "sender should be the current trace source"); | |||
|
|
13 | t.equal(TraceSource.DebugLevel, level, "level should be debug level"); | |||
|
|
14 | t.equal(msg, "Hello, World!", "The message should be formatted correctly"); | |||
|
|
15 | ||||
|
|
16 | t.end(); | |||
| 11 | }); |
|
17 | }); | |
| 12 |
|
18 | |||
|
|
19 | trace.debug("Hello, {0}!", "World"); | |||
|
|
20 | ||||
| 13 | h.destroy(); |
|
21 | h.destroy(); | |
| 14 | }); No newline at end of file |
|
22 | }); | |
| 1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
| 1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
| 1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now
