mirror of
				https://gitlab.com/MrFry/mrfrys-node-server
				synced 2025-04-01 20:24:18 +02:00 
			
		
		
		
	Colorizing logs even more
This commit is contained in:
		@@ -53,20 +53,24 @@ function Log (s, c, b) {
 | 
			
		||||
function LogReq (req, toFile, sc) {
 | 
			
		||||
  try {
 | 
			
		||||
    let ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
 | 
			
		||||
    let logEntry = ip + DELIM + req.hostname + DELIM + req.headers['user-agent'] + DELIM + req.method + DELIM
 | 
			
		||||
 | 
			
		||||
    let rColor = GetRandomColor(ip)
 | 
			
		||||
 | 
			
		||||
    let logEntry = C(rColor) + ip + C()
 | 
			
		||||
    let color = 'green'
 | 
			
		||||
    if (req.url.includes('lred')) {
 | 
			
		||||
      color = 'red'
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    logEntry += C(color) + DELIM + req.hostname + DELIM + req.headers['user-agent'] + DELIM + req.method + DELIM
 | 
			
		||||
 | 
			
		||||
    logEntry += req.url
 | 
			
		||||
 | 
			
		||||
    if (sc !== undefined && sc === 404) { logEntry += DELIM + sc }
 | 
			
		||||
    let color = GetColor('green')
 | 
			
		||||
 | 
			
		||||
    if (req.url.includes('lred')) {
 | 
			
		||||
      color = GetColor('red')
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (req.url.toLowerCase().includes('isadding')) { color = GetColor('yellow') }
 | 
			
		||||
    if (!toFile) {
 | 
			
		||||
      Log(logEntry, color)
 | 
			
		||||
      Log(logEntry + C())
 | 
			
		||||
    } else {
 | 
			
		||||
      let defLogs = GetDateString() + DELIM + logEntry
 | 
			
		||||
 | 
			
		||||
@@ -79,6 +83,10 @@ function LogReq (req, toFile, sc) {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function GetRandomColor (ip) {
 | 
			
		||||
  return 'red'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function GetColor (c) {
 | 
			
		||||
  if (c === 'redbg') { return '\x1b[41m%s\x1b[0m' }
 | 
			
		||||
  if (c === 'bluebg') { return '\x1b[44m%s\x1b[0m' }
 | 
			
		||||
@@ -88,3 +96,16 @@ function GetColor (c) {
 | 
			
		||||
  if (c === 'blue') { return '\x1b[34m%s\x1b[0m' }
 | 
			
		||||
  if (c === 'cyan') { return '\x1b[36m%s\x1b[0m' }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function C (c) {
 | 
			
		||||
  if (c !== undefined) { c = c.toLowerCase() }
 | 
			
		||||
 | 
			
		||||
  if (c === 'redbg') { return '\x1b[41m' }
 | 
			
		||||
  if (c === 'bluebg') { return '\x1b[44m' }
 | 
			
		||||
  if (c === 'red') { return '\x1b[31m' }
 | 
			
		||||
  if (c === 'green') { return '\x1b[32m' }
 | 
			
		||||
  if (c === 'yellow') { return '\x1b[33m' }
 | 
			
		||||
  if (c === 'blue') { return '\x1b[34m' }
 | 
			
		||||
  if (c === 'cyan') { return '\x1b[36m' }
 | 
			
		||||
  if (c === undefined || c === 'clear' || c === 'c') { return '\x1b[0m' }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user