Skip to content

Commit

Permalink
support for html logs
Browse files Browse the repository at this point in the history
  • Loading branch information
bobrik committed Aug 15, 2012
1 parent 7e19896 commit e3bd458
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 22 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -16,6 +16,7 @@ Everybody loves screenshots!
* Send your colleagues links to your favorite logs with your settings and bookmark them.
* Link activation in logs - just click on it to open.
* Whole system and current log activity state indication.
* Support for plain text and html logs.
* Open-source. Can you imagine that?

## Demo
Expand Down Expand Up @@ -51,6 +52,9 @@ PuperGrep needs to know what to monitor. Simple server to make you understand wh
return;
}

// if your log may be interpreted as html:
// manager.setLogType("my_cool_log", "html");

puper.listen(8080, "127.0.0.1");
});
})();
Expand Down
23 changes: 19 additions & 4 deletions lib/LogReaderManager.js
Expand Up @@ -11,25 +11,40 @@
return callback(new Error("Log " + name + " already registered with path " + path));
}

this.logs[name] = path;
this.logs[name] = {
path: path
};

callback();
};

LogReaderManager.prototype.setLogType = function(name, type) {
if (this.logs[name]) {
this.logs[name].type = type;
}
}

LogReaderManager.prototype.getLogReader = function(name, callback) {
if (!this.readers[name]) {
if (!this.logs[name]) {
return callback(new Error("No log defined with name " + name));
}

this.readers[name] = new LogReader(this.logs[name]);
this.readers[name] = new LogReader(this.logs[name].path);
}

callback(undefined, this.readers[name]);
};

LogReaderManager.prototype.getLogsNames = function() {
return Object.keys(this.logs);
LogReaderManager.prototype.getLogs = function() {
var self = this;

return Object.keys(self.logs).map(function(name) {
return {
name: name,
type: self.logs[name].type
};
});
};

module.exports = LogReaderManager;
Expand Down
4 changes: 3 additions & 1 deletion lib/PuperGrep.js
Expand Up @@ -60,7 +60,9 @@
}

socket.emit("logs", {
logs: manager.getLogsNames().sort()
logs: manager.getLogs().sort(function(left, right) {
return left.name.localeCompare(right.name);
})
});

socket.on("subscribe", function(data) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "pupergrep",
"version": "0.5.5",
"version": "0.6.0",
"description": "Real-time grep for your logs right in your favorite modern browser made with Twitter Bootstrap.",
"main": "index.js",
"dependencies": {
Expand Down
39 changes: 23 additions & 16 deletions public/index.html
Expand Up @@ -163,6 +163,7 @@ <h3>Settings<i class="icon-ban-circle" id="health-icon"></i></h3>
connected = false,
healthIconTimer = undefined,
currentLog = undefined,
currentLogType = undefined,
bufferLength = 20,
outputPaused = false,
linkSeparator = '!!!';
Expand Down Expand Up @@ -322,11 +323,11 @@ <h3>Settings<i class="icon-ban-circle" id="health-icon"></i></h3>
name: element.data("log-name")
});

currentLog = element.data("log-name");
currentLog = element.data("log-name");
currentLogType = element.data("log-type");

rebuildCurrentLink();


activeLogHeart = logsListContainer.find("li.log.active .heart");
logsList.each(function(index, node) {
var element = jQuery(node);
Expand All @@ -335,6 +336,7 @@ <h3>Settings<i class="icon-ban-circle" id="health-icon"></i></h3>
element.find(".heart").hide();
}
});

setTimeout(function() {
logHighlighting = false;
}, 1000);
Expand Down Expand Up @@ -391,21 +393,22 @@ <h3>Settings<i class="icon-ban-circle" id="health-icon"></i></h3>

logsListContainer.children(".log").remove();

jQuery(data.logs).each(function(index, name) {
jQuery(data.logs).each(function(index, log) {
var container = jQuery("<li>"),
log = jQuery("<a>"),
link = jQuery("<a>"),
heart = jQuery("<i>");

heart.addClass("icon-heart").addClass("heart").hide();
log.text(name);
log.append(heart);
container.data("log-name", name);
link.text(log.name);
link.append(heart);
container.data("log-name", log.name);
container.data("log-type", log.type);
container.addClass("log");
container.append(log);
container.append(link);

logsListContainer.append(container);

if (name == currentLog) {
if (log.name == currentLog) {
selectLog = container;
}
});
Expand Down Expand Up @@ -440,14 +443,18 @@ <h3>Settings<i class="icon-ban-circle" id="health-icon"></i></h3>
container = jQuery("<tr>");
line = jQuery("<td>");

// escaping html
text = text.split("&").join("&amp;").split( "<").join("&lt;").split(">").join("&gt;");
// making some links
text = text.replace(/(https?:\/\/[^\s]+)/g, function(url) {
return '<a href="' + url + '">' + url + '</a>';
});
if (currentLogType == "html") {
line.html(text);
} else {
// escaping html
text = text.split("&").join("&amp;").split( "<").join("&lt;").split(">").join("&gt;");
// making some links
text = text.replace(/(https?:\/\/[^\s]+)/g, function(url) {
return '<a href="' + url + '">' + url + '</a>';
});

line.html(text);
line.html(text);
}

if (!isGrepAcceptedLine(text)) {
return;
Expand Down

0 comments on commit e3bd458

Please sign in to comment.