From 2022fa9a442ad8e2a7821b6d863ddfd44f174546 Mon Sep 17 00:00:00 2001 From: matlorr Date: Fri, 11 Oct 2024 09:10:39 +0000 Subject: [PATCH] Added logging game-access data --- .gitignore | 1 + relay/index.mjs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/.gitignore b/.gitignore index f6fa519e..e20f104c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ client/dist games/ server/.lake **/.DS_Store +logs/ diff --git a/relay/index.mjs b/relay/index.mjs index 9f9bb6c0..8c4c5b37 100644 --- a/relay/index.mjs +++ b/relay/index.mjs @@ -45,6 +45,18 @@ const server = app const lang = req.params.lang const ip = anonymize(req.headers['x-forwarded-for'] || req.socket.remoteAddress) + const log = `${process.env.HOME}/lean4game/logs/game-access.log` + const header = "date;anon-ip;game;lang\n" + const data = `${new Date()};${ip};${owner}/${repo};${lang}\n` + + fs.writeFile(log, header.concat(data), { flag: 'ax' }, (file_exists) => { + if (file_exists) { + fs.appendFile(log, data, (err) => { + if (err) console.log("Failed to append to log!") + }); + } + }); + console.log(`[${new Date()}] ${ip} requested translation for ${owner}/${repo} in ${lang}`) const filename = req.params[0];