From 564206dd8bb73b0eb91a6cb93d8b0d3c2d7a1d26 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Thu, 1 Oct 2020 21:45:40 -0600 Subject: [PATCH] Begin using the tslog module --- src/events/HostGame.ts | 8 ++++---- src/main.ts | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/events/HostGame.ts b/src/events/HostGame.ts index ed76028..75fcf91 100644 --- a/src/events/HostGame.ts +++ b/src/events/HostGame.ts @@ -13,7 +13,7 @@ that the host is able to just send that to the other players */ import * as db from '../utils/db'; import { Socket } from 'socket.io'; -import { active_games } from '../main'; +import { active_games, log } from '../main'; import { generate_game_code } from '../utils/gamecode'; export const HostGame = (socket: Socket, data: HostGame) => { @@ -29,7 +29,7 @@ export const HostGame = (socket: Socket, data: HostGame) => { active_games[game_code] = game; - console.log(`${data.username} created a game. (Gamecode: ${game_code})`); + log.info(`${data.username} created a game. (Gamecode: ${game_code})`); // Respond to client socket.emit(`HostInformation`, { @@ -38,11 +38,11 @@ export const HostGame = (socket: Socket, data: HostGame) => { players: [data.username] }); } catch (err) { - + log.error(err); // Let client know an error occured socket.emit(`HostInformation`, { success: false, error: `${err.name}: ${err.message}` - }) + }); } }; \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 3432fd7..6c6eed8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,3 +1,4 @@ +import { Logger } from "tslog"; import * as sio from "socket.io"; import { writeFileSync } from "fs"; import { Vote } from "./events/Vote"; @@ -15,6 +16,9 @@ import { NextPresident } from "./events/special/SpecialElection/NextPresident"; import { ExecutiveConfirmation } from "./events/special/ExecutiveConfirmation"; import { InvestigateAffiliation } from "./events/special/InvestigateLoyalty/InvestigateAffiliation"; +export var log: Logger = new Logger({ + displayLogLevel: true, +}); export var active_games: {[key: string]: Game} = {}; @@ -29,7 +33,7 @@ function clean_up() { console.log(`Writing game: ${code} to disk`); writeFileSync(`${db_dir}/${code}`, active_games[code].toJSON()); }; - console.log(`Finished saving games to disk.`); + log.info(`Finished saving games to disk.`); } // Listen to the signals for the cleanup requirement @@ -39,7 +43,7 @@ process.on('SIGINT', clean_up); const io = sio.listen(3000); io.on(`connection`, (socket: sio.Socket) => { - console.log(`Client connected`); + log.info(`Client connected`); // Game Management socket.on(`HostGame`, (data: HostGame) => HostGame(socket, data));