Implement Winston powered logger

This commit is contained in:
Cryptkeeper
2015-11-01 23:46:24 -06:00
parent eb75acf754
commit dec1536c6c
5 changed files with 36 additions and 14 deletions

17
lib/logger.js Normal file
View File

@ -0,0 +1,17 @@
var winston = require('winston');
winston.remove(winston.transports.Console);
winston.add(winston.transports.File, {
filename: 'minetrack.log'
});
winston.add(winston.transports.Console, {
'timestamp': function() {
var date = new Date();
return date.toLocaleTimeString() + " " + date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear().toString().substring(2, 4);
},
'colorize': true
});
module.exports = winston;

View File

@ -4,6 +4,8 @@ var url = require('url');
var mime = require('mime');
var io = require('socket.io');
var logger = require('./logger');
var config = require('../config.json');
exports.start = function(callback) {
@ -15,7 +17,7 @@ exports.start = function(callback) {
urlMapping[routeKeys[i]] = config.routes[routeKeys[i]];
}
console.log(Object.keys(config.routes));
logger.log('info', Object.keys(config.routes));
// Create our tiny little HTTP server.
var server = http.createServer(function(req, res) {
@ -41,7 +43,7 @@ exports.start = function(callback) {
exports.io = (io = io.listen(server));
// Since everything is loaded, do some final prep work.
console.log('Started on %s:%d', config.site.ip, config.site.port);
logger.log('info', 'Started on %s:%d', config.site.ip, config.site.port);
callback();
};