From 434be07a5e2a59d952f618c1aa2b7c920bb93d4d Mon Sep 17 00:00:00 2001 From: Mathew Kurian Date: Mon, 19 May 2014 03:02:27 -0500 Subject: [PATCH] Fixed bugs and added more customizations --- src/index.js | 81 ++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/index.js b/src/index.js index d884df6..2d51f32 100644 --- a/src/index.js +++ b/src/index.js @@ -5,8 +5,9 @@ var util = require('util') , moment = require('moment') , fs = require('fs'); -var APP_NAME = "APP_NAME"; -var LOG_PATH = __dirname + "/log"; +var APP_NAME = "Mus.ec"; +var LOG_PATH = "./scribe"; +var MAIN_USER = "root"; // Logger information which will be read by the 'overload' function when // assigning the roles of each I/O scribes. @@ -83,12 +84,9 @@ var createdir = function(){ var overload = function() { - // Additional transports - console.realtime = console.info; - console.high = console.info; - console.normal = console.info; - console.low = console.info; - + for(var i in loggers.types) + console[i] = console.info; + // Assign this variable as write directory var dayiso = moment().isoWeekday(); // FIXME Remove this var fpath = logpath = createdir(); @@ -123,7 +121,7 @@ var overload = function() { // use the 'arguments' variable instead. var utfs = arguments.length == 1 && typeof arguments[0] === 'object' ? JSON.stringify(arguments[0], null, 4) : util.format.apply(util, arguments).trim() // Moment.js is a great time library for Node.js - , mtime = moment().format('MMMM Do YYYY, h:mm:ss A') + , mtime = moment().format('h:mm:ss A') // Used to show where the tags are to be placed. // I.e. [Memache] Message goes here. // Coldex holds the index of the first ']' @@ -194,45 +192,47 @@ var logger = function(req, res, next) { next(); } -var htmltemplate = ""; -var css = {}; -css['html,body'] = 'margin:0; border:none;float:none;display:block;padding:0;font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif;background:#1c262f;overflow:hidden;'; -css['div'] = 'font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif;font-size:11px;'; -css['html'] = 'background:#2A3946;padding:0;padding-left:50px;' -css['body'] = 'border-left: 1px solid rgba(255, 255, 255, 0.12);'; -css['.log-time'] = 'background: none;color: rgba(255, 255, 255, 0.24);padding:2px 5px;margin-right:2px;margin-left:-1px;font-size:11px;'; -css['.log-type'] = 'background: #633E3E;color: #C20404;padding:2px 5px;margin-right:2px;font-size:11px;'; -css['.log-line'] = 'height:auto;line-height:15px;color:#BEBEBE;font-size:11px;' -css['.button, .selected'] = "font-family:Consolas,Menlo,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New,monospace,serif;background:#2C3338;text-align:center;width:100%;line-height:35px;height:35px;margin-bottom:5px;box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.11);" -css['.selected'] = "background:#4D5961;" -css['a'] = "background:none;text-decoration:none;font-size: 11px;color: #C2C2C2;padding: 10px;" - -htmltemplate+= "TITLE"; -var buttons = '
' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '
' -htmltemplate += '
CONTENT
' + buttons + ''; -htmltemplate = "" + htmltemplate + ""; +var datetemplate = fs.readFileSync(__dirname + "/log.html", { encoding : "utf8"}); var divRegex = loggers.settings.divider.replace(/([\||\$|\^|\?|\[|\]|\)|\(|\{|\}])/g, '\\$1'); var regA = new RegExp('^(.*?)(' + divRegex + ")", 'mg'); var regB = new RegExp('^(.*?)' + divRegex + '\\s{0,}\\[(.*?)\\](.*?)$', 'gm') var regC = new RegExp('^(.*?)' + divRegex,'mg'); +var rndColors = [ "#16a085", "#27ae60", "#2980b9", "#8e44ad", "#f39c12", "#d35400", "#c0392b", "#7f8c8d"] + var getlog = function(req, res) { + var date = req.param('date'); + if(typeof date === 'undefined'){ + var logs = []; + var path = LOG_PATH + "/log"; + fs.readdir(path, function(err, files){ + var reponse = datetemplate.replace("TITLE", APP_NAME + " - " + "Scribe.js Control Panel"); + if(err) return res.send(reponse.replace('CONTENT', err)); + + var loggerDates = ""; + for(var i = 0; i < files.length; i++) + try { + var file = files[i]; + var fileSplit = file.split("_"); + var m = fileSplit[0]; + var d = fileSplit[1]; + var y = "20" + fileSplit[2]; + loggerDates += '
' + m + '
' + d + '
' + y + '
'; + } catch(e) {} + + return res.send(reponse.replace('CONTENT', files.join(",")).replace('LOGGER_DATES', loggerDates) + .replace('LOG_PATH', LOG_PATH) + .replace('LOGGER_USERNAME', MAIN_USER)); + }); + + return; + } + var type = req.param('type'); type = type ? type : "log"; - var contents = "No log found"; - fs.readFile(logpath + "/app." + type, 'utf8', function(err, data) { + var contents = "No log found"; + fs.readFile(LOG_PATH + "/log/" + date + "/" + MAIN_USER + "/app." + type, 'utf8', function(err, data) { if (!err) contents = data; // contents = contents.replace(/^(.*?)#\|#/mg, '$1#\|#') contents = contents.replace(/ /g, ' ') @@ -240,8 +240,7 @@ var getlog = function(req, res) { contents = contents.replace(regB, '$1$2$3'); contents = contents.replace(regC, '$1') contents = contents.replace(/^(.*?)$/mg, '
$1
') - var response = htmltemplate.replace(type + '_', '').replace("CONTENT", contents).replace("TITLE", APP_NAME + " - " + type); - res.send(response); + res.send({ status : 0, data : contents}); }); }