mirror of
https://github.com/wassname/talk.git
synced 2026-07-28 11:27:05 +08:00
* feat: added locale support for Tenant * feat: added secret scrubbing to logs * chore: cleanup logger * chore: logger improvements * feat: re-introduce scoped pretty logger * feat: added initial error support * refactor: replace trace-error.TraceError with talk.InternalError * fix: fixed error logging * refactor: replaced Error with VError * fix: repaired issue with error management on api * fix: patched bug with not found handler * feat: added translations * feat: added location path to invalid entries * refactor: refactored error handling on graph * fix: moved indexing operations to master node * refactor: added throw for when the message isn't found in testing * fix: removed duplicate log * fix: fixed naming on environment variable
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import { ErrorRequestHandler, RequestHandler } from "express";
|
|
import now from "performance-now";
|
|
|
|
import logger from "talk-server/logger";
|
|
|
|
export const accessLogger: RequestHandler = (req, res, next) => {
|
|
const startTime = now();
|
|
const end = res.end;
|
|
res.end = (chunk: any, encodingOrCb?: any, cb?: any) => {
|
|
// Compute the end time.
|
|
const responseTime = Math.round(now() - startTime);
|
|
|
|
// Get some extra goodies from the request.
|
|
const userAgent = req.get("User-Agent");
|
|
|
|
// Reattach the old end, and finish.
|
|
res.end = end;
|
|
if (typeof encodingOrCb === "function") {
|
|
res.end(chunk, encodingOrCb);
|
|
} else {
|
|
res.end(chunk, encodingOrCb, cb);
|
|
}
|
|
|
|
// Log this out.
|
|
logger.info(
|
|
{
|
|
// traceID: req.id,
|
|
url: req.originalUrl || req.url,
|
|
method: req.method,
|
|
statusCode: res.statusCode,
|
|
userAgent,
|
|
responseTime,
|
|
},
|
|
"http request"
|
|
);
|
|
};
|
|
|
|
next();
|
|
};
|
|
|
|
export const errorLogger: ErrorRequestHandler = (err, req, res, next) => {
|
|
logger.error({ err }, "http error");
|
|
|
|
next(err);
|
|
};
|