首页 > Web开发 > 详细

js logger

时间:2017-04-14 19:40:34      阅读:318      评论:0      收藏:0      [点我收藏+]
<span style="color:#CC0000;">这个组件的实现参考了log4net组件的记录方式,我们利用这个js的logger组件,就可以用log的输出的方式来进行你的调试工作了</span>  
  
<pre name="code" class="java">/*  
js调试组件  
*/  
(function () {   
    var logger = function (level, object, viewType) {   
        this.level = level;   
        this.object = object;   
        this.viewType = viewType;   
    }   
    logger.LEVEL_DEBUG = 0;   
    logger.LEVEL_INFO = 1;   
    logger.LEVEL_WARN = 2;   
    logger.LEVEL_ERROR = 3;   
    logger.LEVEL_FATAL = 4;   
    logger.VIEW_TYPE_ALERT = 0;   
    logger.VIEW_TYPE_APPEND = 1;   
    logger.prototype = {   
        setLevel: function (level) {   
            this.level = level;   
        },   
        setObject: function (o) {   
            if (typeof o == string) {   
                this.object = document.getElementById(o);   
            } else {   
                this.object = o;   
            }   
        },   
        setViewType: function (type) {   
            this.viewType = type;   
        },   
        log: function (s) {   
            this.message(100, s);   
        },   
        debug: function (s) {   
            this.message(logger.LEVEL_DEBUG, s);   
        },   
        info: function (s) {   
            this.message(logger.LEVEL_INFO, s);   
        },   
        warn: function (s) {   
            this.message(logger.LEVEL_WARN, s);   
        },   
        error: function (s) {   
            this.message(logger.LEVEL_ERROR, s);   
        },   
        fatal: function (s) {   
            this.message(logger.LEVEL_FATAL, s);   
        },   
        message: function (level, s) {   
            if (level >= this.level) {   
                if (this.object != null) {   
                    this.object.innerHTML = s;   
                } else if (this.viewType == logger.VIEW_TYPE_ALERT) {   
                    alert(s);   
                } else {   
                    document.body.appendChild(document.createTextNode(s));   
                    document.body.appendChild(document.createElement("br"));   
                }   
            }   
        }   
    };   
    if (typeof window.Logger == undefined || window.Logger == null)   
        window.Logger = new logger(logger.LEVEL_DEBUG, null, logger.VIEW_TYPE_APPEND);   
})();  

 

js logger

原文:http://www.cnblogs.com/WhiteHorseIsNotHorse/p/6710345.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!