mirror of
				https://gitlab.com/MrFry/mrfrys-node-server
				synced 2025-04-01 20:24:18 +02:00 
			
		
		
		
	Logging imporvements
This commit is contained in:
		@@ -107,6 +107,7 @@ app.use(vhost('qmining.frylabs.net', qmining))
 | 
			
		||||
app.use(vhost('sio.frylabs.net', sio))
 | 
			
		||||
app.use(vhost('stuff.frylabs.net', stuff))
 | 
			
		||||
app.use(vhost('frylabs.net', main))
 | 
			
		||||
app.use(vhost('www.frylabs.net', main))
 | 
			
		||||
 | 
			
		||||
app.use(vhost('qmining.tk', old))
 | 
			
		||||
app.use(vhost('www.qmining.tk', old))
 | 
			
		||||
 
 | 
			
		||||
@@ -25,7 +25,7 @@ module.exports = {
 | 
			
		||||
  LogReq: LogReq
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const DELIM = '|'
 | 
			
		||||
const DELIM = C('green') + '|' + C()
 | 
			
		||||
 | 
			
		||||
const utils = require('../utils/utils.js')
 | 
			
		||||
const locLogFile = './stats/logs'
 | 
			
		||||
@@ -50,12 +50,12 @@ function GetDateString () {
 | 
			
		||||
    ('0' + m.getSeconds()).slice(-2)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function Log (s, c, b) {
 | 
			
		||||
  if (c !== undefined) { console.log(c, GetDateString() + DELIM + s) } else { console.log(GetDateString() + DELIM + s) }
 | 
			
		||||
function Log (s, c) {
 | 
			
		||||
  let dl = DELIM + C(c)
 | 
			
		||||
  let log = C(c) + GetDateString() + dl + s
 | 
			
		||||
 | 
			
		||||
  if (b) { utils.Beep() }
 | 
			
		||||
 | 
			
		||||
  utils.AppendToFile(GetDateString() + DELIM + s, logFile)
 | 
			
		||||
  console.log(log)
 | 
			
		||||
  utils.AppendToFile(log, logFile)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function LogReq (req, toFile, sc) {
 | 
			
		||||
@@ -63,21 +63,21 @@ function LogReq (req, toFile, sc) {
 | 
			
		||||
    let ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
 | 
			
		||||
 | 
			
		||||
    let logEntry = C(GetRandomColor(ip)) + ip + C()
 | 
			
		||||
    let dl = DELIM
 | 
			
		||||
    if (req.url.includes('lred')) {
 | 
			
		||||
      logEntry += C('red')
 | 
			
		||||
      dl += C('red')
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    logEntry += DELIM + req.hostname + DELIM + req.headers['user-agent'] + DELIM + req.method + DELIM
 | 
			
		||||
    logEntry += dl + req.hostname + dl + req.headers['user-agent'] + dl + req.method + dl
 | 
			
		||||
 | 
			
		||||
    logEntry += req.url
 | 
			
		||||
 | 
			
		||||
    if (sc !== undefined && sc === 404) { logEntry += DELIM + sc }
 | 
			
		||||
    if (sc !== undefined && sc === 404) { logEntry += dl + sc }
 | 
			
		||||
 | 
			
		||||
    if (req.url.toLowerCase().includes('isadding')) { color = GetColor('yellow') }
 | 
			
		||||
    if (!toFile) {
 | 
			
		||||
      Log(logEntry + C())
 | 
			
		||||
    } else {
 | 
			
		||||
      let defLogs = GetDateString() + DELIM + logEntry
 | 
			
		||||
      let defLogs = GetDateString() + dl + logEntry
 | 
			
		||||
 | 
			
		||||
      utils.AppendToFile(defLogs, locLogFile)
 | 
			
		||||
      utils.AppendToFile(defLogs, allLogFile)
 | 
			
		||||
@@ -104,13 +104,7 @@ function GetRandomColor (ip) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function GetColor (c) {
 | 
			
		||||
  if (c === 'redbg') { return '\x1b[41m%s\x1b[0m' }
 | 
			
		||||
  if (c === 'bluebg') { return '\x1b[44m%s\x1b[0m' }
 | 
			
		||||
  if (c === 'red') { return '\x1b[31m%s\x1b[0m' }
 | 
			
		||||
  if (c === 'green') { return '\x1b[32m%s\x1b[0m' }
 | 
			
		||||
  if (c === 'yellow') { return '\x1b[33m%s\x1b[0m' }
 | 
			
		||||
  if (c === 'blue') { return '\x1b[34m%s\x1b[0m' }
 | 
			
		||||
  if (c === 'cyan') { return '\x1b[36m%s\x1b[0m' }
 | 
			
		||||
  return c
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function C (c) {
 | 
			
		||||
@@ -123,5 +117,5 @@ function C (c) {
 | 
			
		||||
  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' }
 | 
			
		||||
  return '\x1b[0m'
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user