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:
		 Submodule public/moodle-test-userscript updated: c935c9e078...de7760ea82
									
								
							@@ -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()
 | 
			
		||||
 
 | 
			
		||||
@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user