1、定義log4js服務類,用於初始化log4javascript相關引數//啟用javascript 日誌功能var logger = log4javascript.getLogger("main");log4javascript.setEnabled(true);var appender = new log4javascript.InPageAppender();appender.layout.pattern = "%d{yyyy-MM-dd HH:mm:ss,SSS} [%c] %-5p - %m{1}%n";logger.addAppender(appender);//點選Ctrl鍵時顯示/隱藏日誌控制檯document.onkeydown = function (evt) {var VK_F9 = 120;//相容IE和Firefox獲得keyBoardEvent物件var evt = (evt) ? evt : ((window.event) ? window.event : "");//相容IE和Firefox獲得keyBoardEvent物件的鍵值var key = evt.keyCode ? evt.keyCode : evt.which;if (evt.ctrlKey) {if (appender.visible) {appender.hide();appender.visible = false;log4javascript.setEnabled(false);} else {log4javascript.setEnabled(true);appender.show();appender.visible = true;}}};2、引入log4javascript.js和log4js3、使用log4javascript記錄日誌$(function () {$("#Button1").click(function () {logger.debug("This is a debugging message from the log4javascript in-page page");logger.info("info info");logger.error("error info");});});
1、定義log4js服務類,用於初始化log4javascript相關引數//啟用javascript 日誌功能var logger = log4javascript.getLogger("main");log4javascript.setEnabled(true);var appender = new log4javascript.InPageAppender();appender.layout.pattern = "%d{yyyy-MM-dd HH:mm:ss,SSS} [%c] %-5p - %m{1}%n";logger.addAppender(appender);//點選Ctrl鍵時顯示/隱藏日誌控制檯document.onkeydown = function (evt) {var VK_F9 = 120;//相容IE和Firefox獲得keyBoardEvent物件var evt = (evt) ? evt : ((window.event) ? window.event : "");//相容IE和Firefox獲得keyBoardEvent物件的鍵值var key = evt.keyCode ? evt.keyCode : evt.which;if (evt.ctrlKey) {if (appender.visible) {appender.hide();appender.visible = false;log4javascript.setEnabled(false);} else {log4javascript.setEnabled(true);appender.show();appender.visible = true;}}};2、引入log4javascript.js和log4js3、使用log4javascript記錄日誌$(function () {$("#Button1").click(function () {logger.debug("This is a debugging message from the log4javascript in-page page");logger.info("info info");logger.error("error info");});});