Browse Source

Improved logging, removed redundant logs.

KrisVos130 8 years ago
parent
commit
b6d3332214

+ 1 - 1
backend/logic/actions/hooks/adminRequired.js

@@ -29,7 +29,7 @@ module.exports = function(next) {
 				logger.info("ADMIN_REQUIRED", `User failed to pass admin required check. "${err}"`);
 				return cb({status: 'failure', message: err});
 			}
-			logger.info("ADMIN_REQUIRED", `User "${session.userId}" passed admin required check.`);
+			logger.info("ADMIN_REQUIRED", `User "${session.userId}" passed admin required check.`, false);
 			args.push(session.userId);
 			next.apply(null, args);
 		});

+ 1 - 1
backend/logic/actions/hooks/loginRequired.js

@@ -23,7 +23,7 @@ module.exports = function(next) {
 				logger.info("LOGIN_REQUIRED", `User failed to pass login required check.`);
 				return cb({status: 'failure', message: err});
 			}
-			logger.info("LOGIN_REQUIRED", `User "${session.userId}" passed login required check.`);
+			logger.info("LOGIN_REQUIRED", `User "${session.userId}" passed login required check.`, false);
 			args.push(session.userId);
 			next.apply(null, args);
 		});

+ 1 - 1
backend/logic/actions/hooks/ownerRequired.js

@@ -35,7 +35,7 @@ module.exports = function(next) {
 				logger.info("OWNER_REQUIRED", `User failed to pass owner required check for station "${stationId}". "${err}"`);
 				return cb({status: 'failure', message: err});
 			}
-			logger.info("OWNER_REQUIRED", `User "${session.userId}" passed owner required check for station "${stationId}"`);
+			logger.info("OWNER_REQUIRED", `User "${session.userId}" passed owner required check for station "${stationId}"`, false);
 			args.push(session.userId);
 			next.apply(null, args);
 		});

+ 2 - 2
backend/logic/actions/news.js

@@ -51,7 +51,7 @@ module.exports = {
 				logger.error("NEWS_INDEX", `Indexing news failed. "${err}"`);
 				return cb({status: 'failure', message: err});
 			}
-			logger.success("NEWS_INDEX", `Indexing news successful.`);
+			logger.success("NEWS_INDEX", `Indexing news successful.`, false);
 			return cb({ status: 'success', data: news });
 		});
 	},
@@ -100,7 +100,7 @@ module.exports = {
 				logger.error("NEWS_NEWEST", `Getting the latest news failed. "${err}"`);
 				return cb({ 'status': 'failure', 'message': err });
 			}
-			logger.success("NEWS_NEWEST", `Successfully got the latest news.`);
+			logger.success("NEWS_NEWEST", `Successfully got the latest news.`, false);
 			return cb({ status: 'success', data: news });
 		});
 	},

+ 5 - 6
backend/logic/actions/stations.js

@@ -78,12 +78,12 @@ setInterval(() => {
 		}
 
 		stationsCountUpdated.forEach((stationId) => {
-			console.log("Updating count of ", stationId);
+			//logger.info("UPDATE_STATION_USER_COUNT", `Updating user count of ${stationId}.`);
 			cache.pub('station.updateUserCount', stationId);
 		});
 
 		stationsUpdated.forEach((stationId) => {
-			console.log("Updating ", stationId);
+			//logger.info("UPDATE_STATION_USER_LIST", `Updating user list of ${stationId}.`);
 			cache.pub('station.updateUsers', stationId);
 		});
 
@@ -241,7 +241,7 @@ module.exports = {
 				logger.error("STATIONS_INDEX", `Indexing stations failed. "${err}"`);
 				return cb({'status': 'failure', 'message': err});
 			}
-			logger.success("STATIONS_INDEX", `Indexing stations successful.`);
+			logger.success("STATIONS_INDEX", `Indexing stations successful.`, false);
 			return cb({'status': 'success', 'stations': stations});
 		});
 	},
@@ -269,7 +269,7 @@ module.exports = {
 				logger.error("STATIONS_FIND_BY_NAME", `Finding station "${stationName}" failed. "${err}"`);
 				return cb({'status': 'failure', 'message': err});
 			}
-			logger.success("STATIONS_FIND_BY_NAME", `Found station "${stationName}" successfully.`);
+			logger.success("STATIONS_FIND_BY_NAME", `Found station "${stationName}" successfully.`, false);
 			cb({status: 'success', data: station});
 		});
 	},
@@ -307,7 +307,7 @@ module.exports = {
 				logger.error("STATIONS_GET_PLAYLIST", `Getting playlist for station "${stationId}" failed. "${err}"`);
 				return cb({ status: 'failure', message: err });
 			} else {
-				logger.success("STATIONS_GET_PLAYLIST", `Got playlist for station "${stationId}" successfully.`);
+				logger.success("STATIONS_GET_PLAYLIST", `Got playlist for station "${stationId}" successfully.`, false);
 				cb({ status: 'success', data: playlist.songs });
 			}
 		});
@@ -355,7 +355,6 @@ module.exports = {
 
 			(station, next) => {
 				utils.socketJoinRoom(session.socketId, `station.${station._id}`);
-				console.log(station.currentSong);
 				let data = {
 					_id: station._id,
 					type: station.type,

+ 8 - 11
backend/logic/io.js

@@ -8,6 +8,7 @@ const async = require('async');
 const cache = require('./cache');
 const utils = require('./utils');
 const db = require('./db');
+const logger = require('./logger');
 
 module.exports = {
 
@@ -45,19 +46,15 @@ module.exports = {
 
 		this.io.on('connection', socket => {
 			socket.ip = socket.request.headers['x-forwarded-for'] || '0.0.0.0';
-			console.info(`User has connected. IP: ${socket.ip}`);
+			let sessionInfo = '';
+			if (socket.session.sessionId) sessionInfo = ` UserID: ${socket.session.userId}.`;
+			logger.info('IO_CONNECTION', `User connected. IP: ${socket.ip}.${sessionInfo}`);
 
 			// catch when the socket has been disconnected
-			socket.on('disconnect', () => {
-
-				// remove the user from their current station (if any)
-				if (socket.session) {
-					//actions.stations.leave(socket.sessionId, result => {});
-					// Remove session from Redis
-					//cache.hdel('sessions', socket.session.sessionId);
-				}
-
-				console.info('User has disconnected');
+			socket.on('disconnect', (reason) => {
+				let sessionInfo = '';
+				if (socket.session.sessionId) sessionInfo = ` UserID: ${socket.session.userId}.`;
+				logger.info('IO_DISCONNECTION', `User disconnected. IP: ${socket.ip}.${sessionInfo}`);
 			});
 
 			// catch errors on the socket (internal to socket.io)

+ 8 - 8
backend/logic/logger.js

@@ -105,37 +105,37 @@ module.exports = {
 
 		cb();
 	},
-	success: (type, message) => {
+	success: (type, message, display = true) => {
 		success++;
 		successThisMinute++;
 		successThisHour++;
 		let time = getTimeFormatted();
 		fs.appendFile(dir + '/all.log', `${time} SUCCESS - ${type} - ${message}\n`, ()=>{});
 		fs.appendFile(dir + '/success.log', `${time} SUCCESS - ${type} - ${message}\n`, ()=>{});
-		console.info('\x1b[32m', time, 'SUCCESS', '-', type, '-', message, '\x1b[0m');
+		if (display) console.info('\x1b[32m', time, 'SUCCESS', '-', type, '-', message, '\x1b[0m');
 	},
-	error: (type, message) => {
+	error: (type, message, display = true) => {
 		error++;
 		errorThisMinute++;
 		errorThisHour++;
 		let time = getTimeFormatted();
 		fs.appendFile(dir + '/all.log', `${time} ERROR - ${type} - ${message}\n`, ()=>{});
 		fs.appendFile(dir + '/error.log', `${time} ERROR - ${type} - ${message}\n`, ()=>{});
-		console.warn('\x1b[31m', time, 'ERROR', '-', type, '-', message, '\x1b[0m');
+		if (display) console.warn('\x1b[31m', time, 'ERROR', '-', type, '-', message, '\x1b[0m');
 	},
-	info: (type, message) => {
+	info: (type, message, display = true) => {
 		info++;
 		infoThisMinute++;
 		infoThisHour++;
 		let time = getTimeFormatted();
 		fs.appendFile(dir + '/all.log', `${time} INFO - ${type} - ${message}\n`, ()=>{});
 		fs.appendFile(dir + '/info.log', `${time} INFO - ${type} - ${message}\n`, ()=>{});
-		console.info('\x1b[36m', time, 'INFO', '-', type, '-', message, '\x1b[0m');
+		if (display) console.info('\x1b[36m', time, 'INFO', '-', type, '-', message, '\x1b[0m');
 	},
-	stationIssue: (string) => {
+	stationIssue: (string, display = false) => {
 		let time = getTimeFormatted();
 		fs.appendFile(dir + '/debugStation.log', `${time} - ${string}\n`, ()=>{});
-		console.info('\x1b[35m', time, '-', string, '\x1b[0m');
+		if (display) console.info('\x1b[35m', time, '-', string, '\x1b[0m');
 	},
 	calculatePerSecond: function(number) {
 		let secondsRunning = Math.floor((Date.now() - started) / 1000);

+ 1 - 1
backend/logic/stations.js

@@ -282,7 +282,7 @@ module.exports = {
 	},
 
 	skipStation: function(stationId) {
-		console.log("SKIP!", stationId);
+		logger.info("STATION_SKIP", `Skipping station ${stationId}.`, false);
 		let _this = this;
 		return (cb) => {
 			if (typeof cb !== 'function') cb = ()=>{};

+ 2 - 2
backend/logic/tasks.js

@@ -17,7 +17,7 @@ let testTask = (callback) => {
 };
 
 let checkStationSkipTask = (callback) => {
-	logger.info("TASK_STATIONS_SKIP_CHECK", `Checking for stations to be skipped.`);
+	logger.info("TASK_STATIONS_SKIP_CHECK", `Checking for stations to be skipped.`, false);
 	async.waterfall([
 		(next) => {
 			cache.hgetall('stations', next);
@@ -42,7 +42,7 @@ let checkStationSkipTask = (callback) => {
 };
 
 let sessionClearingTask = (callback) => {
-	logger.info("TASK_SESSION_CLEAR", `Checking for sessions to be cleared.`);
+	logger.info("TASK_SESSION_CLEAR", `Checking for sessions to be cleared.`, false);
 	async.waterfall([
 		(next) => {
 			cache.hgetall('sessions', next);