Skip to content

Commit

Permalink
Added library
Browse files Browse the repository at this point in the history
  • Loading branch information
amaurer committed Dec 11, 2012
1 parent 3e08952 commit 714a742
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,5 +10,6 @@ lib-cov
pids
logs
results
node_modules

npm-debug.log
119 changes: 119 additions & 0 deletions log-massage.js
@@ -0,0 +1,119 @@


function LogMassage(){

this.data = [];
this.stringData = "";
this.rowDelimiter = "\n";
this.cellDelimiter = "\",\"";

if(arguments.length !== 0){
var constructorArgType = typeof arguments[0];
if(constructorArgType === "object" && arguments[0] instanceof Buffer){
constructorArgType = "buffer";
};
switch(constructorArgType){
case "buffer" :
case "string" :
this.stringData = arguments[0].toString();
this.toArrays(this.stringData);
case "object" :
/* Config */
if(arguments[0].data != null) this.data = arguments[0].data;
if(arguments[0].stringData != null) this.stringData = arguments[0].stringData;
if(arguments[0].rowDelimiter != null) this.rowDelimiter = arguments[0].rowDelimiter;
if(arguments[0].cellDelimiter != null) this.cellDelimiter = arguments[0].cellDelimiter;
};
};
};

LogMassage.prototype.toArrays = function(stringData){
if(typeof stringData !== "string") return this;

var i, ii, len, lenn, x, tmp;
var logResults = [];
var rows = stringData.toString().split(this.rowDelimiter);
var cells = [];
for (i = 1, len = rows.length; i<len; i++) {
x = rows[i];
if(x === "" || x.length === 0) continue;
cells = x.split(this.cellDelimiter);
tmp = [];
for (ii = 0, lenn = cells.length; ii<lenn; ii++) {
tmp.push(
cells[ii].replace(/"/g, "").replace(/\r/g, "")
);
};
logResults.push(tmp);
};
this.data = logResults;
return this;
};

LogMassage.prototype.removeRow = function(rowNum){
this.data = this.data.splice(rowNum, 1);
return this;
};

LogMassage.prototype.removeRowCells = function(startCell, endCell){
/* arguments are cells */
var i, len;
for (i = 1, len = this.data.length; i<len; i++) {
this.removeCell.call(this, i, startCell, endCell);
};
return this;
};

LogMassage.prototype.removeCell = function(rowNum, startCell, endCell){
/* Cant do this, cells change poisitions */
this.data[rowNum].splice(startCell, endCell);
return this;
};

LogMassage.prototype.eachRow = function(eachFunction, context) {
var i, len, x;
for (i = 0, len = this.data.length; i<len; i++) {
eachFunction.call(context || this, i, this.data[i]);
};
return this;
};

LogMassage.prototype.eachCell = function(eachFunction, context) {
var i, ii, len, lenn, x;
for (i = 0, len = this.data.length; i<len; i++) {
x = this.data[i];
for (ii = 0, lenn = x.length; ii<lenn; ii++) {
eachFunction.call(context || this, ii, x[ii], i, x);
};
};
return this;
};

LogMassage.prototype.eachCellByPosition = function(pos, eachFunction, context) {
var i, len, x;
for (i = 0, len = this.data.length; i<len; i++) {
x = this.data[i];
eachFunction.call(context || this, x[pos], i, x);
};
return this;
};

LogMassage.prototype.toDate = function() {
var i, ii, len, lenn, x, fields;
for (i = 0, len = this.data.length; i<len; i++) {
x = this.data[i];
fields = [];
for (ii = 0, lenn = arguments.length; ii<lenn; ii++) {
fields.push(x[arguments[ii]]);
fields.push(" ");
};
fields.pop(); // remove extra space
x.push(
new Date(fields.join(""))
);
};
return this;
};

module.exports = LogMassage;

20 changes: 20 additions & 0 deletions main.js
@@ -0,0 +1,20 @@
var fs = require("fs");
var LogMassage = require("./log-massage.js");

var logFilePath = "X:\\JRun4\\servers\\OEMLR_Sean\\cfusion.ear\\cfusion.war\\WEB-INF\\cfusion\\logs\\Dean.log";
var filterRange = [
new Date("12/04/12").getTime(),
new Date("12/03/12").getTime()
];


fs.readFile(logFilePath, function(e, data){

var lm = new LogMassage(data);
lm
.toDate(2, 3)
.removeRowCells(1, 4)

console.log(lm);

});

0 comments on commit 714a742

Please sign in to comment.