Logging fixes / imporvements, voteTodo api

This commit is contained in:
mrfry 2020-11-29 10:04:18 +01:00
parent 4e34267d44
commit 865e97a754
6 changed files with 66 additions and 38 deletions

View file

@ -112,7 +112,7 @@ function Log(msg: string | object, color?: string): void {
function LogReq(
req: any /*express.Request*/,
toFile?: boolean,
sc?: string
statusCode?: string
): void {
try {
const ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
@ -124,7 +124,7 @@ function LogReq(
return
}
let logEntry = GetRandomColor(ip) + ip + C()
let logEntry = logHashed(ip)
let dl = DELIM
if (req.url.includes('lred')) {
dl += C('red')
@ -141,7 +141,13 @@ function LogReq(
)
}
logEntry +=
dl + hostname + dl + req.headers['user-agent'] + dl + req.method + dl
dl +
logHashed(hostname) +
dl +
req.headers['user-agent'] +
dl +
req.method +
dl
if (req.session && req.session.user) {
logEntry += C('cyan') + req.session.user.id + C() + dl
@ -153,8 +159,8 @@ function LogReq(
logEntry += GetRandomColor(req.url.split('?')[0]) + req.url
if (sc !== undefined) {
logEntry += dl + sc
if (statusCode !== undefined) {
logEntry += dl + statusCode
}
logEntry += C()
@ -385,7 +391,7 @@ function C(color?: string): string {
if (color === 'magenta') {
return '\x1b[35m'
}
if (color === 'coloryan') {
if (color === 'cyan') {
return '\x1b[36m'
}
return '\x1b[0m'