Browse Source

Improved request logging

update-deps
Alex Mikhalev 7 years ago
parent
commit
93a9523442
  1. 15
      server/logging/prettyPrint.ts

15
server/logging/prettyPrint.ts

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
import * as chalk from "chalk";
import pretty = require("pino/pretty");
type Level = "default" | 60 | 50 | 40 | 30 | 20 | 10;
@ -37,7 +36,13 @@ function formatter(value: any) { @@ -37,7 +36,13 @@ function formatter(value: any) {
// }
// line += value.pid + " on " + value.hostname + ")";
const isRequest = value.req && value.res;
line += ": ";
if (isRequest) {
line += chalk.reset(formatRequest(value));
return line;
}
if (value.msg) {
line += chalk.cyan(value.msg);
}
@ -50,6 +55,14 @@ function formatter(value: any) { @@ -50,6 +55,14 @@ function formatter(value: any) {
return line;
}
function formatRequest(value: any): string {
const matches = /Content-Length: (\d+)/.exec(value.res.header);
const contentLength = matches ? matches[1] : null;
return `${value.req.remoteAddress} - ` +
`"${value.req.method} ${value.req.url} ${value.res.statusCode}" ` +
`${value.responseTime} ms - ${contentLength}`;
}
function withSpaces(value: string): string {
const lines = value.split("\n");
for (let i = 1; i < lines.length; i++) {

Loading…
Cancel
Save