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

@ -1 +1 @@
Subproject commit c935c9e078303b98d61d2d12bca3ab86e2695bdc
Subproject commit de7760ea8262febe71e697c697e3c34a87eb10df

View file

@ -95,9 +95,17 @@ setLogTimer()
const app = express()
const loggableKeywords = [
'user.js'
]
app.use(function (req, res, next) {
res.on('finish', function () {
logger.LogReq(req, true, res.statusCode)
let toLog = loggableKeywords.some((x) => {
return req.url.includes(x)
})
if (toLog) { logger.LogReq(req) }
if (res.statusCode !== 404) { stat.LogStat(req.url) }
})
next()

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) {