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 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}`);
}