mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Logging improvements
This commit is contained in:
parent
0336860a9d
commit
21f5ba8af5
1 changed files with 33 additions and 10 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue