Skip to content

Commit

Permalink
Fix: Lining up stats in debug logger when ms length differs (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
adampash authored Aug 8, 2016
1 parent e33f742 commit 164daec
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/packages/logger/request-logger/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ ${stats.map(({ type, name, duration, controller }) => {
name = `${yellow(controller)}#${name}`;
}
return `${duration >= 10 ? duration : ` ${duration}`} ms ${name}`;
return `${pad(startTime, endTime, duration)} ms ${name}`;
}).join('\n')}
${stats.reduce((total, { duration }) => total + duration, 0)} ms Total
${pad(startTime,
endTime,
stats.reduce((total, { duration }) => total + duration, 0))} ms Total
${(endTime - startTime).toString()} ms Actual\
`;

Expand Down Expand Up @@ -77,3 +79,19 @@ Processed ${cyan(`${method}`)} "${path}" ${magenta('Params')} ${
: null
}
`;

/**
* @private
*/
function countDigits(num: number) {
return Math.floor(Math.log10(num) + 1);
}

/**
* @private
*/
function pad(startTime: number, endTime: number, duration: number) {
const maxLength = countDigits(endTime - startTime);

return ' '.repeat(maxLength - countDigits(duration)) + duration;
}

0 comments on commit 164daec

Please sign in to comment.