32
32
*
33
33
* @publicapi @module trace
34
34
*/
35
- /* tslint:disable:no-console */
36
35
import { parse } from '../common/hof' ;
37
36
import { isFunction , isNumber } from '../common/predicates' ;
38
37
import { Transition } from '../transition/transition' ;
39
38
import { ViewTuple } from '../view' ;
40
39
import { ActiveUIView , ViewConfig , ViewContext } from '../view/interface' ;
41
40
import { stringify , functionToString , maxLength , padString } from './strings' ;
41
+ import { safeConsole } from './safeConsole' ;
42
42
import { Resolvable } from '../resolve/resolvable' ;
43
43
import { PathNode } from '../path/pathNode' ;
44
44
import { PolicyWhen } from '../resolve/interface' ;
@@ -57,22 +57,14 @@ function uiViewString(uiview: ActiveUIView) {
57
57
const viewConfigString = ( viewConfig : ViewConfig ) => {
58
58
const view = viewConfig . viewDecl ;
59
59
const state = view . $context . name || '(root)' ;
60
- return `[View#${ viewConfig . $id } from '${ state } ' state]: target ui-view: '${ view . $uiViewName } @${
61
- view . $uiViewContextAnchor
62
- } '`;
60
+ return `[View#${ viewConfig . $id } from '${ state } ' state]: target ui-view: '${ view . $uiViewName } @${ view . $uiViewContextAnchor } '` ;
63
61
} ;
64
62
65
63
/** @hidden */
66
64
function normalizedCat ( input : Category | string ) : string {
67
65
return isNumber ( input ) ? Category [ input ] : Category [ Category [ input ] ] ;
68
66
}
69
67
70
- /** @hidden */
71
- const consoleLog = Function . prototype . bind . call ( console . log , console ) ;
72
-
73
- /** @hidden */
74
- const consoletable = isFunction ( console . table ) ? console . table . bind ( console ) : consoleLog . bind ( console ) ;
75
-
76
68
/**
77
69
* Trace categories Enum
78
70
*
@@ -176,13 +168,13 @@ export class Trace {
176
168
/** @internalapi called by ui-router code */
177
169
traceTransitionStart ( trans : Transition ) {
178
170
if ( ! this . enabled ( Category . TRANSITION ) ) return ;
179
- console . log ( `${ transLbl ( trans ) } : Started -> ${ stringify ( trans ) } ` ) ;
171
+ safeConsole . log ( `${ transLbl ( trans ) } : Started -> ${ stringify ( trans ) } ` ) ;
180
172
}
181
173
182
174
/** @internalapi called by ui-router code */
183
175
traceTransitionIgnored ( trans : Transition ) {
184
176
if ( ! this . enabled ( Category . TRANSITION ) ) return ;
185
- console . log ( `${ transLbl ( trans ) } : Ignored <> ${ stringify ( trans ) } ` ) ;
177
+ safeConsole . log ( `${ transLbl ( trans ) } : Ignored <> ${ stringify ( trans ) } ` ) ;
186
178
}
187
179
188
180
/** @internalapi called by ui-router code */
@@ -191,45 +183,45 @@ export class Trace {
191
183
const event = parse ( 'traceData.hookType' ) ( options ) || 'internal' ,
192
184
context = parse ( 'traceData.context.state.name' ) ( options ) || parse ( 'traceData.context' ) ( options ) || 'unknown' ,
193
185
name = functionToString ( ( step as any ) . registeredHook . callback ) ;
194
- console . log ( `${ transLbl ( trans ) } : Hook -> ${ event } context: ${ context } , ${ maxLength ( 200 , name ) } ` ) ;
186
+ safeConsole . log ( `${ transLbl ( trans ) } : Hook -> ${ event } context: ${ context } , ${ maxLength ( 200 , name ) } ` ) ;
195
187
}
196
188
197
189
/** @internalapi called by ui-router code */
198
190
traceHookResult ( hookResult : HookResult , trans : Transition , transitionOptions : any ) {
199
191
if ( ! this . enabled ( Category . HOOK ) ) return ;
200
- console . log ( `${ transLbl ( trans ) } : <- Hook returned: ${ maxLength ( 200 , stringify ( hookResult ) ) } ` ) ;
192
+ safeConsole . log ( `${ transLbl ( trans ) } : <- Hook returned: ${ maxLength ( 200 , stringify ( hookResult ) ) } ` ) ;
201
193
}
202
194
203
195
/** @internalapi called by ui-router code */
204
196
traceResolvePath ( path : PathNode [ ] , when : PolicyWhen , trans ?: Transition ) {
205
197
if ( ! this . enabled ( Category . RESOLVE ) ) return ;
206
- console . log ( `${ transLbl ( trans ) } : Resolving ${ path } (${ when } )` ) ;
198
+ safeConsole . log ( `${ transLbl ( trans ) } : Resolving ${ path } (${ when } )` ) ;
207
199
}
208
200
209
201
/** @internalapi called by ui-router code */
210
202
traceResolvableResolved ( resolvable : Resolvable , trans ?: Transition ) {
211
203
if ( ! this . enabled ( Category . RESOLVE ) ) return ;
212
- console . log (
204
+ safeConsole . log (
213
205
`${ transLbl ( trans ) } : <- Resolved ${ resolvable } to: ${ maxLength ( 200 , stringify ( resolvable . data ) ) } `
214
206
) ;
215
207
}
216
208
217
209
/** @internalapi called by ui-router code */
218
210
traceError ( reason : any , trans : Transition ) {
219
211
if ( ! this . enabled ( Category . TRANSITION ) ) return ;
220
- console . log ( `${ transLbl ( trans ) } : <- Rejected ${ stringify ( trans ) } , reason: ${ reason } ` ) ;
212
+ safeConsole . log ( `${ transLbl ( trans ) } : <- Rejected ${ stringify ( trans ) } , reason: ${ reason } ` ) ;
221
213
}
222
214
223
215
/** @internalapi called by ui-router code */
224
216
traceSuccess ( finalState : StateObject , trans : Transition ) {
225
217
if ( ! this . enabled ( Category . TRANSITION ) ) return ;
226
- console . log ( `${ transLbl ( trans ) } : <- Success ${ stringify ( trans ) } , final state: ${ finalState . name } ` ) ;
218
+ safeConsole . log ( `${ transLbl ( trans ) } : <- Success ${ stringify ( trans ) } , final state: ${ finalState . name } ` ) ;
227
219
}
228
220
229
221
/** @internalapi called by ui-router code */
230
222
traceUIViewEvent ( event : string , viewData : ActiveUIView , extra = '' ) {
231
223
if ( ! this . enabled ( Category . UIVIEW ) ) return ;
232
- console . log ( `ui-view: ${ padString ( 30 , event ) } ${ uiViewString ( viewData ) } ${ extra } ` ) ;
224
+ safeConsole . log ( `ui-view: ${ padString ( 30 , event ) } ${ uiViewString ( viewData ) } ${ extra } ` ) ;
233
225
}
234
226
235
227
/** @internalapi called by ui-router code */
@@ -257,19 +249,19 @@ export class Trace {
257
249
} )
258
250
. sort ( ( a , b ) => ( a [ uivheader ] || '' ) . localeCompare ( b [ uivheader ] || '' ) ) ;
259
251
260
- consoletable ( mapping ) ;
252
+ safeConsole . table ( mapping ) ;
261
253
}
262
254
263
255
/** @internalapi called by ui-router code */
264
256
traceViewServiceEvent ( event : string , viewConfig : ViewConfig ) {
265
257
if ( ! this . enabled ( Category . VIEWCONFIG ) ) return ;
266
- console . log ( `VIEWCONFIG: ${ event } ${ viewConfigString ( viewConfig ) } ` ) ;
258
+ safeConsole . log ( `VIEWCONFIG: ${ event } ${ viewConfigString ( viewConfig ) } ` ) ;
267
259
}
268
260
269
261
/** @internalapi called by ui-router code */
270
262
traceViewServiceUIViewEvent ( event : string , viewData : ActiveUIView ) {
271
263
if ( ! this . enabled ( Category . VIEWCONFIG ) ) return ;
272
- console . log ( `VIEWCONFIG: ${ event } ${ uiViewString ( viewData ) } ` ) ;
264
+ safeConsole . log ( `VIEWCONFIG: ${ event } ${ uiViewString ( viewData ) } ` ) ;
273
265
}
274
266
}
275
267
0 commit comments