preparation for file logs

This commit is contained in:
Baipyrus 2023-01-18 15:24:44 +01:00
parent f50975cf7a
commit 0ffc9c16a2

View File

@ -1,4 +1,5 @@
const logging = true; const fileLogging = false;
const consoleLogging = true;
const fs = require('fs'); const fs = require('fs');
const http = require('http'); const http = require('http');
@ -22,8 +23,8 @@ app.get('/connect', (req, res) => {
name: "", name: "",
id id
}); });
if (logging) if (consoleLogging)
console.log(`User connected with ID '${id}'.`); console.log(`User with ID '${id}' connected.`);
res.status(200).json({ id }); res.status(200).json({ id });
}); });
@ -31,7 +32,7 @@ app.post('/disconnect', (req, res) => {
const { id } = req.body; const { id } = req.body;
for (let i = 0; i < users.length; i++) for (let i = 0; i < users.length; i++)
if (users[i].id === id) { if (users[i].id === id) {
if (logging) if (consoleLogging)
console.log(`User with ID '${id}' disconnected.`); console.log(`User with ID '${id}' disconnected.`);
users.splice(i, 1); users.splice(i, 1);
break; break;
@ -52,7 +53,7 @@ app.post('/nickname', (req, res) => {
if (success) { if (success) {
for (const u of users) for (const u of users)
if (u.id === id) { if (u.id === id) {
if (logging) if (consoleLogging)
console.log(`(Re-)named user with ID '${id}'.`); console.log(`(Re-)named user with ID '${id}'.`);
u.name = name; u.name = name;
break; break;
@ -90,7 +91,7 @@ app.post('/getChat', (req, res) => {
return; return;
} }
if (logging) if (consoleLogging)
console.log(`Delivered messages to user with ID '${id}'.`); console.log(`Delivered messages to user with ID '${id}'.`);
res.status(200).json(chats); res.status(200).json(chats);
@ -111,7 +112,7 @@ app.post('/message', (req, res) => {
let user = `User '${ownName}'`; let user = `User '${ownName}'`;
if (!ownName) if (!ownName)
user = ownName = "Anonymous" user = ownName = "Anonymous"
if (logging) { if (consoleLogging) {
const idStr = (!ownName) ? ` ID: ${id}.` : ''; const idStr = (!ownName) ? ` ID: ${id}.` : '';
console.log(`${user} sent message '${message}'.${idStr}`); console.log(`${user} sent message '${message}'.${idStr}`);
} }