Improved request logging
This commit is contained in:
parent
a698775388
commit
93a9523442
@ -1,5 +1,4 @@
|
|||||||
import * as chalk from "chalk";
|
import * as chalk from "chalk";
|
||||||
|
|
||||||
import pretty = require("pino/pretty");
|
import pretty = require("pino/pretty");
|
||||||
|
|
||||||
type Level = "default" | 60 | 50 | 40 | 30 | 20 | 10;
|
type Level = "default" | 60 | 50 | 40 | 30 | 20 | 10;
|
||||||
@ -37,7 +36,13 @@ function formatter(value: any) {
|
|||||||
// }
|
// }
|
||||||
// line += value.pid + " on " + value.hostname + ")";
|
// line += value.pid + " on " + value.hostname + ")";
|
||||||
|
|
||||||
|
const isRequest = value.req && value.res;
|
||||||
|
|
||||||
line += ": ";
|
line += ": ";
|
||||||
|
if (isRequest) {
|
||||||
|
line += chalk.reset(formatRequest(value));
|
||||||
|
return line;
|
||||||
|
}
|
||||||
if (value.msg) {
|
if (value.msg) {
|
||||||
line += chalk.cyan(value.msg);
|
line += chalk.cyan(value.msg);
|
||||||
}
|
}
|
||||||
@ -50,6 +55,14 @@ function formatter(value: any) {
|
|||||||
return line;
|
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 {
|
function withSpaces(value: string): string {
|
||||||
const lines = value.split("\n");
|
const lines = value.split("\n");
|
||||||
for (let i = 1; i < lines.length; i++) {
|
for (let i = 1; i < lines.length; i++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user