Skip to content

Commit

Permalink
Also log to the javascript console when available
Browse files Browse the repository at this point in the history
  • Loading branch information
gashcrumb committed Oct 22, 2013
1 parent e30b4b2 commit bc6cf19
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions hawtio-web/src/main/webapp/index.html
Expand Up @@ -253,7 +253,32 @@ <h2 title="Status Code: {{connectFailure.status}}">Cannot Connect: {{connectFail
}
}

var MyConsole = window.console;
var consoleLogger = null;

if ('console' in window) {

var MyConsole = window.console;
consoleLogger = function(messages, context) {
var hdlr = MyConsole.log;

// Prepend the logger's name to the log message for easy identification.
if (context.name) {
messages[0] = "[" + context.name + "] " + messages[0];
}

// Delegate through to custom warn/error loggers if present on the console.
if (context.level === Logger.WARN && MyConsole.warn) {
hdlr = MyConsole.warn;
} else if (context.level === Logger.ERROR && MyConsole.error) {
hdlr = MyConsole.error;
} else if (context.level === Logger.INFO && MyConsole.info) {
hdlr = MyConsole.info;
}

hdlr.apply(MyConsole, messages);
};
}


Logger.setHandler(function(messages, context) {
// MyConsole.log("context: ", context);
Expand All @@ -278,7 +303,7 @@ <h2 title="Status Code: {{connectFailure.status}}">Cannot Connect: {{connectFail
}
}

node.innerHTML = text;
node.textContent = text;
node.className = context.level.name;
panel.appendChild(node);
if (panel.childNodes.length > parseInt(window['LogBuffer'])) {
Expand All @@ -292,30 +317,11 @@ <h2 title="Status Code: {{connectFailure.status}}">Cannot Connect: {{connectFail
if (panel.scrollTop > panel.scrollHeight - container.scrollHeight - 100) {
panel.scrollTop = panel.scrollHeight;
}

});

/*
Logger.setHandler(function(messages, context) {
var hdlr = MyConsole.log;
// Prepend the logger's name to the log message for easy identification.
if (context.name) {
messages[0] = "[" + context.name + "] " + messages[0];
}
// Delegate through to custom warn/error loggers if present on the console.
if (context.level === Logger.WARN && MyConsole.warn) {
hdlr = MyConsole.warn;
} else if (context.level === Logger.ERROR && MyConsole.error) {
hdlr = MyConsole.error;
} else if (context.level === Logger.INFO && MyConsole.info) {
hdlr = MyConsole.info;
if (consoleLogger) {
consoleLogger(messages, context);
}

hdlr.apply(MyConsole, messages);
});
*/

// sneaky hack to redirect console.log !
window.console = {
Expand Down

0 comments on commit bc6cf19

Please sign in to comment.