Skip to content

Commit

Permalink
fix(trace): Show function definition during logging of trace.enable('…
Browse files Browse the repository at this point in the history
…HOOK')
  • Loading branch information
christopherthielen committed Sep 19, 2016
1 parent dfe3c7a commit 190d122
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/common/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ function promiseToString(p: Promise<any>) {
export function functionToString(fn: Function) {
let fnStr = fnToString(fn);
let namedFunctionMatch = fnStr.match(/^(function [^ ]+\([^)]*\))/);
return namedFunctionMatch ? namedFunctionMatch[1] : fnStr;
let toStr = namedFunctionMatch ? namedFunctionMatch[1] : fnStr;

let fnName = fn['name'] || "";
if (fnName && toStr.match(/function \(/)) {
return 'function ' + fnName + toStr.substr(9);
}
return toStr;
}

export function fnToString(fn: IInjectable) {
Expand Down
9 changes: 4 additions & 5 deletions src/common/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,17 @@ export class Trace {
digest = this.approximateDigests,
event = parse("traceData.hookType")(options) || "internal",
context = parse("traceData.context.state.name")(options) || parse("traceData.context")(options) || "unknown",
name = functionToString((step as any).hookFn);
name = functionToString((step as any).eventHook.callback);
console.log(`Transition #${tid} Digest #${digest}: Hook -> ${event} context: ${context}, ${maxLength(200, name)}`);
}

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

/** called by ui-router code */
Expand Down

0 comments on commit 190d122

Please sign in to comment.