From 0ffc9c16a2dfc0e8486fb63f72256ed3bdf3dff1 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Wed, 18 Jan 2023 15:24:44 +0100 Subject: [PATCH] preparation for file logs --- index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 3e04cc8..56e5643 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ -const logging = true; +const fileLogging = false; +const consoleLogging = true; const fs = require('fs'); const http = require('http'); @@ -22,8 +23,8 @@ app.get('/connect', (req, res) => { name: "", id }); - if (logging) - console.log(`User connected with ID '${id}'.`); + if (consoleLogging) + console.log(`User with ID '${id}' connected.`); res.status(200).json({ id }); }); @@ -31,7 +32,7 @@ app.post('/disconnect', (req, res) => { const { id } = req.body; for (let i = 0; i < users.length; i++) if (users[i].id === id) { - if (logging) + if (consoleLogging) console.log(`User with ID '${id}' disconnected.`); users.splice(i, 1); break; @@ -52,7 +53,7 @@ app.post('/nickname', (req, res) => { if (success) { for (const u of users) if (u.id === id) { - if (logging) + if (consoleLogging) console.log(`(Re-)named user with ID '${id}'.`); u.name = name; break; @@ -90,7 +91,7 @@ app.post('/getChat', (req, res) => { return; } - if (logging) + if (consoleLogging) console.log(`Delivered messages to user with ID '${id}'.`); res.status(200).json(chats); @@ -111,7 +112,7 @@ app.post('/message', (req, res) => { let user = `User '${ownName}'`; if (!ownName) user = ownName = "Anonymous" - if (logging) { + if (consoleLogging) { const idStr = (!ownName) ? ` ID: ${id}.` : ''; console.log(`${user} sent message '${message}'.${idStr}`); }