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:
parent
344ae366fe
commit
6b02caac9a
2 changed files with 14 additions and 19 deletions
|
@ -107,6 +107,7 @@ app.use(vhost('qmining.frylabs.net', qmining))
|
||||||
app.use(vhost('sio.frylabs.net', sio))
|
app.use(vhost('sio.frylabs.net', sio))
|
||||||
app.use(vhost('stuff.frylabs.net', stuff))
|
app.use(vhost('stuff.frylabs.net', stuff))
|
||||||
app.use(vhost('frylabs.net', main))
|
app.use(vhost('frylabs.net', main))
|
||||||
|
app.use(vhost('www.frylabs.net', main))
|
||||||
|
|
||||||
app.use(vhost('qmining.tk', old))
|
app.use(vhost('qmining.tk', old))
|
||||||
app.use(vhost('www.qmining.tk', old))
|
app.use(vhost('www.qmining.tk', old))
|
||||||
|
|
|
@ -25,7 +25,7 @@ module.exports = {
|
||||||
LogReq: LogReq
|
LogReq: LogReq
|
||||||
}
|
}
|
||||||
|
|
||||||
const DELIM = '|'
|
const DELIM = C('green') + '|' + C()
|
||||||
|
|
||||||
const utils = require('../utils/utils.js')
|
const utils = require('../utils/utils.js')
|
||||||
const locLogFile = './stats/logs'
|
const locLogFile = './stats/logs'
|
||||||
|
@ -50,12 +50,12 @@ function GetDateString () {
|
||||||
('0' + m.getSeconds()).slice(-2)
|
('0' + m.getSeconds()).slice(-2)
|
||||||
}
|
}
|
||||||
|
|
||||||
function Log (s, c, b) {
|
function Log (s, c) {
|
||||||
if (c !== undefined) { console.log(c, GetDateString() + DELIM + s) } else { console.log(GetDateString() + DELIM + s) }
|
let dl = DELIM + C(c)
|
||||||
|
let log = C(c) + GetDateString() + dl + s
|
||||||
|
|
||||||
if (b) { utils.Beep() }
|
console.log(log)
|
||||||
|
utils.AppendToFile(log, logFile)
|
||||||
utils.AppendToFile(GetDateString() + DELIM + s, logFile)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function LogReq (req, toFile, sc) {
|
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 ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
|
||||||
|
|
||||||
let logEntry = C(GetRandomColor(ip)) + ip + C()
|
let logEntry = C(GetRandomColor(ip)) + ip + C()
|
||||||
|
let dl = DELIM
|
||||||
if (req.url.includes('lred')) {
|
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
|
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) {
|
if (!toFile) {
|
||||||
Log(logEntry + C())
|
Log(logEntry + C())
|
||||||
} else {
|
} else {
|
||||||
let defLogs = GetDateString() + DELIM + logEntry
|
let defLogs = GetDateString() + dl + logEntry
|
||||||
|
|
||||||
utils.AppendToFile(defLogs, locLogFile)
|
utils.AppendToFile(defLogs, locLogFile)
|
||||||
utils.AppendToFile(defLogs, allLogFile)
|
utils.AppendToFile(defLogs, allLogFile)
|
||||||
|
@ -104,13 +104,7 @@ function GetRandomColor (ip) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetColor (c) {
|
function GetColor (c) {
|
||||||
if (c === 'redbg') { return '\x1b[41m%s\x1b[0m' }
|
return c
|
||||||
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' }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function C (c) {
|
function C (c) {
|
||||||
|
@ -123,5 +117,5 @@ function C (c) {
|
||||||
if (c === 'yellow') { return '\x1b[33m' }
|
if (c === 'yellow') { return '\x1b[33m' }
|
||||||
if (c === 'blue') { return '\x1b[34m' }
|
if (c === 'blue') { return '\x1b[34m' }
|
||||||
if (c === 'cyan') { return '\x1b[36m' }
|
if (c === 'cyan') { return '\x1b[36m' }
|
||||||
if (c === undefined || c === 'clear' || c === 'c') { return '\x1b[0m' }
|
return '\x1b[0m'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue