| @@ -47,8 +47,7 function ActivatableMixin<TBase extends | |||
|
|
47 | 47 | try { |
|
|
48 | 48 | await this.onActivated(ct); |
|
|
49 | 49 | } catch(e) { |
|
|
50 | log.error(e); | |
|
|
51 | // TODO log error | |
|
|
50 | log.error("Suppressed onActivated error: {0}", e); | |
|
|
52 | 51 |
|
|
|
53 | 52 | this.completeSuccess(); |
|
|
54 | 53 | } catch (e) { |
| @@ -76,8 +75,8 function ActivatableMixin<TBase extends | |||
|
|
76 | 75 | this._active = false; |
|
|
77 | 76 | try { |
|
|
78 | 77 | await this.onDeactivated(ct); |
|
|
79 | } catch { | |
|
|
80 | // TODO log error | |
|
|
78 | } catch(e) { | |
|
|
79 | log.error("Suppressed onDeactivated error: {0}", e); | |
|
|
81 | 80 |
|
|
|
82 | 81 | this.completeSuccess(); |
|
|
83 | 82 | } catch (e) { |
| @@ -90,7 +89,7 function ActivatableMixin<TBase extends | |||
|
|
90 | 89 | } |
|
|
91 | 90 | |
|
|
92 | 91 | namespace ActivatableMixin { |
|
|
93 | ||
|
|
92 | export const traceSource = log; | |
|
|
94 | 93 | } |
|
|
95 | 94 | |
|
|
96 | 95 | export = ActivatableMixin; No newline at end of file |
| @@ -133,28 +133,60 class TraceSource { | |||
|
|
133 | 133 | this.emit(TraceSource.WarnLevel, format(msg, args)); |
|
|
134 | 134 | } |
|
|
135 | 135 | |
|
|
136 | /** | |
|
|
137 | * returns true if errors will be recorded. | |
|
|
138 | */ | |
|
|
136 | 139 | isErrorEnabled() { |
|
|
137 | 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 | 149 | error(msg: string, ...args: any[]) { |
|
|
141 | 150 | if (this.isEnabled(TraceSource.ErrorLevel)) |
|
|
142 | 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 | 160 | isEnabled(level: number) { |
|
|
146 | 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 | 170 | traceEvent(level: number, arg: any) { |
|
|
150 | 171 | if (this.isEnabled(level)) |
|
|
151 | 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 | 181 | static on(handler: TraceSourceHandler) { |
|
|
155 | 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 | 190 | static get(id: any) { |
|
|
159 | 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 | 6 | tape('', t => { |
|
|
7 | 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 | 21 | h.destroy(); |
|
|
14 | 22 | }); No newline at end of file |
|
|
1 | NO CONTENT: file was removed |
|
|
1 | NO CONTENT: file was removed |
|
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now
