diff --git a/public/moodle-test-userscript b/public/moodle-test-userscript index c935c9e..de7760e 160000 --- a/public/moodle-test-userscript +++ b/public/moodle-test-userscript @@ -1 +1 @@ -Subproject commit c935c9e078303b98d61d2d12bca3ab86e2695bdc +Subproject commit de7760ea8262febe71e697c697e3c34a87eb10df diff --git a/server.js b/server.js index 1d11978..eef8795 100644 --- a/server.js +++ b/server.js @@ -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() diff --git a/utils/logger.js b/utils/logger.js index 42b72be..e3bc9ac 100644 --- a/utils/logger.js +++ b/utils/logger.js @@ -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) {