javascript Logger
이번 프로젝에서 javascript가 많아서 하나 만들어 봤음..
자바스크립 맨처음위치에
<script type='text/javascript' src='./Logger.js'></script>
만 삽입하고, 코드에서
Logger.debug( String );
Logger.error( String, Exception );
Logger.info( String );
이렇게 사용하면 됨
// Logger.js
function Logger(){}
Logger.disabled = false;
Logger.level = 3; // 1:error, 2:debug, 3:info
Logger.logPane = null;
Logger.logBox = null;
Logger.getDate = function(){
var d = new Date();
return d.getYear() + "/" + d.getMonth() + "/" + d.getDate() + " " + d.getHours() + ":" + d.getMinutes() + " " + d.getSeconds() + "," + d.getMilliseconds();
}
Logger.getLogPane = function(){
if( Logger.logBox != null ) return Logger.logBox;
if( top.document.getElementById("logBox") != null ){
Logger.logBox = top.document.getElementById("logBox");
}
if( Logger.disabled ) return null;
var widthPos = top.document.body.clientWidth;
Logger.logPane = top.document.createElement("div");
Logger.logPane.style.position = "absolute";
Logger.logPane.style.posTop = 550;
Logger.logPane.style.posLeft = "0";
Logger.logPane.style.posWidth = widthPos;
Logger.logPane.style.posHeight = 150;
Logger.logPane.style.visibility = "visible";
Logger.logPane.style.display = "inline";
Logger.logPane.setAttribute("id","logPane");
Logger.logBox = top.document.createElement("textarea");
Logger.logBox.setAttribute("id","logBox");
Logger.logBox.setAttribute("cols","100");
Logger.logBox.setAttribute("rows","10");
Logger.logPane.appendChild( Logger.logBox );
top.document.body.appendChild( Logger.logPane );
return Logger.logBox;
}
Logger.error = function( msg, ex ){
if( Logger.disabled || Logger.level < 1 ) return;
var text = "ERROR ==> " + Logger.getDate() + " " + msg + " Exception: " + ex.description + "\n";
Logger.logging( text );
}
Logger.debug = function( msg ){
if( Logger.disabled || Logger.level < 2 ) return;
var text = "DEBUG ==> " + Logger.getDate() + " " + msg + "\n";
Logger.logging( text );
}
Logger.info = function( msg ){
if( Logger.disabled || Logger.level < 3 ) return;
var text = "INFO ==> " + Logger.getDate() + " " + msg + "\n";
Logger.logging( text );
}
Logger.logging = function( text ){
var logger = Logger.getLogPane();
logger.value += text;
}