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 {
|
function LogReq(req: Request, toFile?: boolean, statusCode?: string): void {
|
||||||
try {
|
try {
|
||||||
const ip: any =
|
let ip: any =
|
||||||
req.headers['cf-connecting-ip'] || req.connection.remoteAddress
|
req.headers['cf-connecting-ip'] || req.connection.remoteAddress
|
||||||
|
if (!toFile) {
|
||||||
|
ip = expandWithSpaces(ip, 35)
|
||||||
|
}
|
||||||
const nolog = noLogips.some((noLogip) => {
|
const nolog = noLogips.some((noLogip) => {
|
||||||
return ip.includes(noLogip)
|
return ip.includes(noLogip)
|
||||||
})
|
})
|
||||||
|
@ -139,20 +148,34 @@ function LogReq(req: Request, toFile?: boolean, statusCode?: string): void {
|
||||||
GetColor('redbg')
|
GetColor('redbg')
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if (!toFile) {
|
||||||
|
hostname = expandWithSpaces(hostname, 7)
|
||||||
|
}
|
||||||
|
|
||||||
logEntry += dl + logHashed(hostname) + dl
|
logEntry += dl + logHashed(hostname) + dl
|
||||||
if (toFile) {
|
if (toFile) {
|
||||||
logEntry += req.headers['user-agent'] + dl
|
logEntry += req.headers['user-agent'] + dl
|
||||||
}
|
}
|
||||||
logEntry += req.method + dl
|
let method = req.method
|
||||||
|
if (!toFile) {
|
||||||
if (req.session && req.session.user) {
|
method = expandWithSpaces(method, 4)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
logEntry += GetRandomColor(req.url.split('?')[0]) + req.url
|
||||||
|
|
||||||
if (statusCode !== undefined) {
|
if (statusCode !== undefined) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue