Permalink
Browse files

support for html logs

  • Loading branch information...
1 parent 7e19896 commit e3bd4588b9860832a057f1f8fbf0b25f58158a53 @bobrik committed Aug 15, 2012
Showing with 50 additions and 22 deletions.
  1. +4 −0 README.md
  2. +19 −4 lib/LogReaderManager.js
  3. +3 −1 lib/PuperGrep.js
  4. +1 −1 package.json
  5. +23 −16 public/index.html
View
@@ -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
@@ -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");
});
})();
View
@@ -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;
View
@@ -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) {
View
@@ -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": {
View
@@ -163,6 +163,7 @@
connected = false,
healthIconTimer = undefined,
currentLog = undefined,
+ currentLogType = undefined,
bufferLength = 20,
outputPaused = false,
linkSeparator = '!!!';
@@ -322,11 +323,11 @@
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);
@@ -335,6 +336,7 @@
element.find(".heart").hide();
}
});
+
setTimeout(function() {
logHighlighting = false;
}, 1000);
@@ -391,21 +393,22 @@
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;
}
});
@@ -440,14 +443,18 @@
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;

0 comments on commit e3bd458

Please sign in to comment.