diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 2b551fe..a8e106c 100755 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -111,11 +111,20 @@ function Log(msg: string | object, color?: string): void { ) } +function expandWithSpaces(text, count) { + while (text.length < count) { + text += ' ' + } + return text +} + function LogReq(req: Request, toFile?: boolean, statusCode?: string): void { try { - const ip: any = + let ip: any = req.headers['cf-connecting-ip'] || req.connection.remoteAddress - + if (!toFile) { + ip = expandWithSpaces(ip, 35) + } const nolog = noLogips.some((noLogip) => { return ip.includes(noLogip) }) @@ -139,20 +148,34 @@ function LogReq(req: Request, toFile?: boolean, statusCode?: string): void { GetColor('redbg') ) } + if (!toFile) { + hostname = expandWithSpaces(hostname, 7) + } + logEntry += dl + logHashed(hostname) + dl if (toFile) { logEntry += req.headers['user-agent'] + dl } - logEntry += req.method + dl - - if (req.session && req.session.user) { - logEntry += C('cyan') + req.session.user.id + C() + dl - } else if (req.session && req.session.isException === true) { - logEntry += C('cyan') + 'EX' + C() + dl - } else { - logEntry += C('red') + 'NOUSER' + C() + dl + let method = req.method + if (!toFile) { + method = expandWithSpaces(method, 4) } + logEntry += method + dl + + let uid = '' + if (req.session && req.session.user) { + uid = req.session.user.id.toString() + } else if (req.session && req.session.isException === true) { + uid = 'EX' + } else { + uid = 'NOUSR' + } + if (!toFile) { + uid = expandWithSpaces(uid, 5) + } + logEntry += C('cyan') + uid + C() + dl + logEntry += GetRandomColor(req.url.split('?')[0]) + req.url if (statusCode !== undefined) {