mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
ditto.http.response: use error level when status >= 500
This commit is contained in:
parent
5f99bddb42
commit
449daf1e35
3 changed files with 273 additions and 1 deletions
226
log.json
Normal file
226
log.json
Normal file
File diff suppressed because one or more lines are too long
45
scripts/deparameterize.ts
Normal file
45
scripts/deparameterize.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
const decoder = new TextDecoder();
|
||||||
|
|
||||||
|
for await (const chunk of Deno.stdin.readable) {
|
||||||
|
const text = decoder.decode(chunk);
|
||||||
|
|
||||||
|
const { sql, parameters } = JSON.parse(text) as { sql: string; parameters: unknown[] };
|
||||||
|
|
||||||
|
let result = sql;
|
||||||
|
|
||||||
|
for (let i = 0; i < parameters.length; i++) {
|
||||||
|
const param = parameters[i];
|
||||||
|
|
||||||
|
result = result.replace(`$${i + 1}`, serializeParameter(param));
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(result + ';');
|
||||||
|
}
|
||||||
|
|
||||||
|
function serializeParameter(param: unknown): string {
|
||||||
|
if (param === null) {
|
||||||
|
return 'null';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof param === 'string') {
|
||||||
|
return `'${param}'`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof param === 'number' || typeof param === 'boolean') {
|
||||||
|
return param.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param instanceof Date) {
|
||||||
|
return `'${param.toISOString()}'`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(param)) {
|
||||||
|
return `'{${param.join(',')}}'`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof param === 'object') {
|
||||||
|
return `'${JSON.stringify(param)}'`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return JSON.stringify(param);
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,7 @@ export const logiMiddleware: MiddlewareHandler = async (c, next) => {
|
||||||
|
|
||||||
const end = new Date();
|
const end = new Date();
|
||||||
const delta = (end.getTime() - start.getTime()) / 1000;
|
const delta = (end.getTime() - start.getTime()) / 1000;
|
||||||
|
const level = c.res.status >= 500 ? 'error' : 'info';
|
||||||
|
|
||||||
logi({ level: 'info', ns: 'ditto.http.response', method, pathname, status: c.res.status, delta });
|
logi({ level, ns: 'ditto.http.response', method, pathname, status: c.res.status, delta });
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue