mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Add ip to logiMiddleware
This commit is contained in:
parent
d458fc8464
commit
381cbfd36f
1 changed files with 4 additions and 2 deletions
|
|
@ -7,7 +7,9 @@ export const logiMiddleware: DittoMiddleware = async (c, next) => {
|
||||||
const { method } = c.req;
|
const { method } = c.req;
|
||||||
const { pathname } = new URL(c.req.url);
|
const { pathname } = new URL(c.req.url);
|
||||||
|
|
||||||
logi({ level: 'info', ns: 'ditto.http.request', method, pathname, requestId });
|
const ip = c.req.header('x-real-ip');
|
||||||
|
|
||||||
|
logi({ level: 'info', ns: 'ditto.http.request', method, pathname, ip, requestId });
|
||||||
|
|
||||||
const start = new Date();
|
const start = new Date();
|
||||||
|
|
||||||
|
|
@ -17,5 +19,5 @@ export const logiMiddleware: DittoMiddleware = async (c, next) => {
|
||||||
const duration = (end.getTime() - start.getTime()) / 1000;
|
const duration = (end.getTime() - start.getTime()) / 1000;
|
||||||
const level = c.res.status >= 500 ? 'error' : 'info';
|
const level = c.res.status >= 500 ? 'error' : 'info';
|
||||||
|
|
||||||
logi({ level, ns: 'ditto.http.response', method, pathname, status: c.res.status, duration, requestId });
|
logi({ level, ns: 'ditto.http.response', method, pathname, status: c.res.status, duration, ip, requestId });
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue