3232 *
3333 *@publicapi @module trace
3434 */
35- /* tslint:disable:no-console */
3635import { parse } from '../common/hof' ;
3736import { isFunction , isNumber } from '../common/predicates' ;
3837import { Transition } from '../transition/transition' ;
3938import { ViewTuple } from '../view' ;
4039import { ActiveUIView , ViewConfig , ViewContext } from '../view/interface' ;
4140import { stringify , functionToString , maxLength , padString } from './strings' ;
41+ import { safeConsole } from './safeConsole' ;
4242import { Resolvable } from '../resolve/resolvable' ;
4343import { PathNode } from '../path/pathNode' ;
4444import { PolicyWhen } from '../resolve/interface' ;
@@ -57,22 +57,14 @@ function uiViewString(uiview: ActiveUIView) {
5757const viewConfigString = ( viewConfig :ViewConfig ) => {
5858const view = viewConfig . viewDecl ;
5959const 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 } '` ;
6361} ;
6462
6563/**@hidden */
6664function normalizedCat ( input :Category | string ) :string {
6765return isNumber ( input ) ?Category [ input ] :Category [ Category [ input ] ] ;
6866}
6967
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-
7668/**
7769 * Trace categories Enum
7870 *
@@ -176,13 +168,13 @@ export class Trace {
176168/**@internalapi called by ui-router code */
177169traceTransitionStart ( trans :Transition ) {
178170if ( ! this . enabled ( Category . TRANSITION ) ) return ;
179- console . log ( `${ transLbl ( trans ) } : Started ->${ stringify ( trans ) } ` ) ;
171+ safeConsole . log ( `${ transLbl ( trans ) } : Started ->${ stringify ( trans ) } ` ) ;
180172}
181173
182174/**@internalapi called by ui-router code */
183175traceTransitionIgnored ( trans :Transition ) {
184176if ( ! this . enabled ( Category . TRANSITION ) ) return ;
185- console . log ( `${ transLbl ( trans ) } : Ignored <>${ stringify ( trans ) } ` ) ;
177+ safeConsole . log ( `${ transLbl ( trans ) } : Ignored <>${ stringify ( trans ) } ` ) ;
186178}
187179
188180/**@internalapi called by ui-router code */
@@ -191,45 +183,45 @@ export class Trace {
191183const event = parse ( 'traceData.hookType' ) ( options ) || 'internal' ,
192184context = parse ( 'traceData.context.state.name' ) ( options ) || parse ( 'traceData.context' ) ( options ) || 'unknown' ,
193185name = 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 ) } ` ) ;
195187}
196188
197189/**@internalapi called by ui-router code */
198190traceHookResult ( hookResult :HookResult , trans :Transition , transitionOptions :any ) {
199191if ( ! 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 ) ) } ` ) ;
201193}
202194
203195/**@internalapi called by ui-router code */
204196traceResolvePath ( path :PathNode [ ] , when :PolicyWhen , trans ?:Transition ) {
205197if ( ! this . enabled ( Category . RESOLVE ) ) return ;
206- console . log ( `${ transLbl ( trans ) } : Resolving${ path } (${ when } )` ) ;
198+ safeConsole . log ( `${ transLbl ( trans ) } : Resolving${ path } (${ when } )` ) ;
207199}
208200
209201/**@internalapi called by ui-router code */
210202traceResolvableResolved ( resolvable :Resolvable , trans ?:Transition ) {
211203if ( ! this . enabled ( Category . RESOLVE ) ) return ;
212- console . log (
204+ safeConsole . log (
213205`${ transLbl ( trans ) } : <- Resolved${ resolvable } to:${ maxLength ( 200 , stringify ( resolvable . data ) ) } `
214206) ;
215207}
216208
217209/**@internalapi called by ui-router code */
218210traceError ( reason :any , trans :Transition ) {
219211if ( ! 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 } ` ) ;
221213}
222214
223215/**@internalapi called by ui-router code */
224216traceSuccess ( finalState :StateObject , trans :Transition ) {
225217if ( ! 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 } ` ) ;
227219}
228220
229221/**@internalapi called by ui-router code */
230222traceUIViewEvent ( event :string , viewData :ActiveUIView , extra = '' ) {
231223if ( ! 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 } ` ) ;
233225}
234226
235227/**@internalapi called by ui-router code */
@@ -257,19 +249,19 @@ export class Trace {
257249} )
258250. sort ( ( a , b ) => ( a [ uivheader ] || '' ) . localeCompare ( b [ uivheader ] || '' ) ) ;
259251
260- consoletable ( mapping ) ;
252+ safeConsole . table ( mapping ) ;
261253}
262254
263255/**@internalapi called by ui-router code */
264256traceViewServiceEvent ( event :string , viewConfig :ViewConfig ) {
265257if ( ! this . enabled ( Category . VIEWCONFIG ) ) return ;
266- console . log ( `VIEWCONFIG:${ event } ${ viewConfigString ( viewConfig ) } ` ) ;
258+ safeConsole . log ( `VIEWCONFIG:${ event } ${ viewConfigString ( viewConfig ) } ` ) ;
267259}
268260
269261/**@internalapi called by ui-router code */
270262traceViewServiceUIViewEvent ( event :string , viewData :ActiveUIView ) {
271263if ( ! this . enabled ( Category . VIEWCONFIG ) ) return ;
272- console . log ( `VIEWCONFIG:${ event } ${ uiViewString ( viewData ) } ` ) ;
264+ safeConsole . log ( `VIEWCONFIG:${ event } ${ uiViewString ( viewData ) } ` ) ;
273265}
274266}
275267