Last active
December 15, 2015 20:41
Capturar errores de Javascript
http://elblogdepicodev.blogspot.com/2013/04/capturar-errores-de-javascript.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>¡Html Error!</title> | |
<script type="text/javascript" src="js/require.js" data-main="js/main"></script> | |
<script type="text/javascript"> | |
requirejs.config({ | |
shim: { | |
'log4javascript': { | |
exports: 'log4javascript' | |
} | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
<h1>¡Html Error!</h1> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(['log4javascript'], function(log4j) { | |
var log4j = log4javascript; | |
var ajaxAppender = new log4j.AjaxAppender('http://localhost:8080/html-error/ajaxAppender'); | |
var ajaxLayout = new log4j.PatternLayout('%d{HH:mm:ss} %-5p %c %m%n'); | |
ajaxAppender.setLayout(ajaxLayout); | |
ajaxAppender.setThreshold(log4j.Level.INFO); | |
log4j.setEnabled(true); | |
var log = log4j.getLogger('es.com.blogspot.elblogdepicodev.log4javascript'); | |
log.addAppender(ajaxAppender); | |
// Capturador de errores javascript | |
window.onerror = function(message, url, linenumber) { | |
log.error(message + ", " + url + ", " + linenumber); | |
} | |
// ¡Atención!: La siguiente linea de código va a producir un error | |
error; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment