mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Even more logging coloring
This commit is contained in:
parent
873d12ef73
commit
6104d2fb4d
3 changed files with 14 additions and 5 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit c935c9e078303b98d61d2d12bca3ab86e2695bdc
|
Subproject commit de7760ea8262febe71e697c697e3c34a87eb10df
|
|
@ -95,9 +95,17 @@ setLogTimer()
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
|
const loggableKeywords = [
|
||||||
|
'user.js'
|
||||||
|
]
|
||||||
|
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
res.on('finish', function () {
|
res.on('finish', function () {
|
||||||
logger.LogReq(req, true, res.statusCode)
|
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) }
|
if (res.statusCode !== 404) { stat.LogStat(req.url) }
|
||||||
})
|
})
|
||||||
next()
|
next()
|
||||||
|
|
|
@ -42,12 +42,13 @@ const colors = [
|
||||||
|
|
||||||
function GetDateString () {
|
function GetDateString () {
|
||||||
const m = new Date()
|
const m = new Date()
|
||||||
return m.getFullYear() + '/' +
|
const d = m.getFullYear() + '/' +
|
||||||
('0' + (m.getMonth() + 1)).slice(-2) + '/' +
|
('0' + (m.getMonth() + 1)).slice(-2) + '/' +
|
||||||
('0' + m.getDate()).slice(-2) + ' ' +
|
('0' + m.getDate()).slice(-2) + ' ' +
|
||||||
('0' + m.getHours()).slice(-2) + ':' +
|
('0' + m.getHours()).slice(-2) + ':' +
|
||||||
('0' + m.getMinutes()).slice(-2) + ':' +
|
('0' + m.getMinutes()).slice(-2) + ':' +
|
||||||
('0' + m.getSeconds()).slice(-2)
|
('0' + m.getSeconds()).slice(-2)
|
||||||
|
return GetRandomColor(m.getHours().toString()) + d + C()
|
||||||
}
|
}
|
||||||
|
|
||||||
function Log (s, c) {
|
function Log (s, c) {
|
||||||
|
@ -62,7 +63,7 @@ function LogReq (req, toFile, sc) {
|
||||||
try {
|
try {
|
||||||
let ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
|
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
|
let dl = DELIM
|
||||||
if (req.url.includes('lred')) {
|
if (req.url.includes('lred')) {
|
||||||
dl += C('red')
|
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 += 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 }
|
if (sc !== undefined && sc === 404) { logEntry += dl + sc }
|
||||||
|
|
||||||
|
@ -97,7 +98,7 @@ function GetRandomColor (ip) {
|
||||||
let res = ip.split('').reduce((res, x) => {
|
let res = ip.split('').reduce((res, x) => {
|
||||||
return res + x.charCodeAt(0)
|
return res + x.charCodeAt(0)
|
||||||
}, 0)
|
}, 0)
|
||||||
return colors[res % colors.length]
|
return C(colors[res % colors.length])
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetColor (c) {
|
function GetColor (c) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue