From 6b02caac9a42051e498e9c0bb5d684681641e2a1 Mon Sep 17 00:00:00 2001
From: MrFry <mrfry@airmail.cc>
Date: Tue, 8 Oct 2019 17:01:44 +0200
Subject: [PATCH] Logging imporvements

---
 server.js       |  1 +
 utils/logger.js | 32 +++++++++++++-------------------
 2 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/server.js b/server.js
index 7955cf9..67fdd25 100644
--- a/server.js
+++ b/server.js
@@ -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))
diff --git a/utils/logger.js b/utils/logger.js
index 0e715fa..44d0994 100644
--- a/utils/logger.js
+++ b/utils/logger.js
@@ -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'
 }