Even more logging coloring

This commit is contained in:
MrFry 2019-10-13 10:49:19 +02:00
parent 873d12ef73
commit 6104d2fb4d
3 changed files with 14 additions and 5 deletions

View file

@ -42,12 +42,13 @@ const colors = [
function GetDateString () {
const m = new Date()
return m.getFullYear() + '/' +
const d = m.getFullYear() + '/' +
('0' + (m.getMonth() + 1)).slice(-2) + '/' +
('0' + m.getDate()).slice(-2) + ' ' +
('0' + m.getHours()).slice(-2) + ':' +
('0' + m.getMinutes()).slice(-2) + ':' +
('0' + m.getSeconds()).slice(-2)
return GetRandomColor(m.getHours().toString()) + d + C()
}
function Log (s, c) {
@ -62,7 +63,7 @@ function LogReq (req, toFile, sc) {
try {
let ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
let logEntry = C(GetRandomColor(ip)) + ip + C()
let logEntry = GetRandomColor(ip) + ip + C()
let dl = DELIM
if (req.url.includes('lred')) {
dl += C('red')
@ -70,7 +71,7 @@ function LogReq (req, toFile, sc) {
logEntry += dl + req.hostname + dl + req.headers['user-agent'] + dl + req.method + dl
logEntry += C(GetRandomColor(req.url.split('?')[0])) + req.url
logEntry += GetRandomColor(req.url.split('?')[0]) + req.url
if (sc !== undefined && sc === 404) { logEntry += dl + sc }
@ -97,7 +98,7 @@ function GetRandomColor (ip) {
let res = ip.split('').reduce((res, x) => {
return res + x.charCodeAt(0)
}, 0)
return colors[res % colors.length]
return C(colors[res % colors.length])
}
function GetColor (c) {