Skip to content

Commit 190d122

Browse files
fix(trace): Show function definition during logging of trace.enable('HOOK')
1 parent dfe3c7a commit 190d122

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/common/strings.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ function promiseToString(p: Promise<any>) {
5757
export function functionToString(fn: Function) {
5858
let fnStr = fnToString(fn);
5959
let namedFunctionMatch = fnStr.match(/^(function [^ ]+\([^)]*\))/);
60-
return namedFunctionMatch ? namedFunctionMatch[1] : fnStr;
60+
let toStr = namedFunctionMatch ? namedFunctionMatch[1] : fnStr;
61+
62+
let fnName = fn['name'] || "";
63+
if (fnName && toStr.match(/function \(/)) {
64+
return 'function ' + fnName + toStr.substr(9);
65+
}
66+
return toStr;
6167
}
6268

6369
export function fnToString(fn: IInjectable) {

src/common/trace.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,17 @@ export class Trace {
162162
digest = this.approximateDigests,
163163
event = parse("traceData.hookType")(options) || "internal",
164164
context = parse("traceData.context.state.name")(options) || parse("traceData.context")(options) || "unknown",
165-
name = functionToString((step as any).hookFn);
165+
name = functionToString((step as any).eventHook.callback);
166166
console.log(`Transition #${tid} Digest #${digest}: Hook -> ${event} context: ${context}, ${maxLength(200, name)}`);
167167
}
168168

169169
/** called by ui-router code */
170-
traceHookResult(hookResult: HookResult, transitionResult: Promise<any>, transitionOptions: any) {
170+
traceHookResult(hookResult: HookResult, transitionOptions: any) {
171171
if (!this.enabled(Category.HOOK)) return;
172172
let tid = parse("transition.$id")(transitionOptions),
173173
digest = this.approximateDigests,
174-
hookResultStr = stringify(hookResult),
175-
transitionResultStr = stringify(transitionResult);
176-
console.log(`Transition #${tid} Digest #${digest}: <- Hook returned: ${maxLength(200, hookResultStr)}, transition result: ${maxLength(200, transitionResultStr)}`);
174+
hookResultStr = stringify(hookResult);
175+
console.log(`Transition #${tid} Digest #${digest}: <- Hook returned: ${maxLength(200, hookResultStr)}`);
177176
}
178177

179178
/** called by ui-router code */

0 commit comments

Comments
 (0)