如何在包装Firebug(或类似)控制台api时访问行号 [英] How to access line numbers when wrapping Firebug (or similar) Console api

查看:163
本文介绍了如何在包装Firebug(或类似)控制台api时访问行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这个工作正常,唯一的问题是firebug(或者其他的)其他控制台)将总是报告日志来自的线路号作为控制台API本身被调用的行。



您建议我如何建立控制台日志我调用我的包装函数的行号?



我宁愿使用跨浏览器解决方案,但是如果firebug插件可能是一个好的开始。 / p>

fyi我调用我的日志功能如下:

  db.log (db.LogLevel.WARN,Blah Blah Blah); 


解决方案

所以这最近又出现了,所以我决定重新它。



现在我年纪大了,更明智的是,我明白了一个更好的解决方案,然后我想做的是调用控制台功能,因为他们是,但有选择地替换他们当水平下降时具有虚拟功能。这给我细致的日志记录和准确的行号报告。我之前的解决方案丢失了一些功能,但我认为这是一个可以接受的妥协。



这里是我的新日志记录库的一部分,显示主要解决方案

  ... 
级别:[debug,info,warn,error],

init:function(minLevel){
var params = abm.getUrlParams();
minLevel = params [debug] || minLevel;

// TODO:firebug lite
window.console = window.console || {};

var clear = false;
for(var i = 0; i var level = self.levels [i];
originalFunctions [i] = originalFunctions [i]
|| console [level] ||倒退;

if(level&&(clear || level === minLevel)){
console [level] = originalFunctions [i];
clear = true;
} else {
console [level] = suppressed(level);
}
}

}
...

您可以在这里查看完整内容: https://github.com/antiBaconMachine/abm-日志


I have wrapped the console API to provide granular logging levels as well as few other sugar features.

This works fine, the only problem is that firebug (or whatever other console) will always report the line number the log came from as the line the console API itself is invoked.

How would you suggest I make the console log the line number at which I call my wrapper function?

I would prefer a cross browser solution but failing that a firebug plugin could be a good start.

fyi I call my loging function like so:

db.log(db.LogLevel.WARN, "Blah Blah Blah");

解决方案

So this recently came up again so I decided to revisit it.

Now I'm older and wiser it's clear to me a much better solution then what I was trying to do is to call the console functions as they are but selectively replace them with dummy functions when the level is turned down. This gives me fine grained logging and accurate line number reporting. A few features have been lost from my previous solution but I think this is an acceptable compromise.

Here's a partial snip of my new logging lib which shows the main solution

...
levels : ["debug","info","warn","error"],

    init : function(minLevel) {
        var params = abm.getUrlParams();
        minLevel = params["debug"] || minLevel;

        //TODO: firebug lite
        window.console = window.console || {};

        var clear = false;
        for (var i=0; i<self.levels.length; i++) {
            var level = self.levels[i];
            originalFunctions[i] = originalFunctions[i] 
            || console[level] || fallback;

            if (level && (clear || level===minLevel)) {
                console[level] = originalFunctions[i];
                clear=true;
            } else {
                console[level] = suppressed(level);
            }
        }

    }
...

You can see the full thing here: https://github.com/antiBaconMachine/abm-log

这篇关于如何在包装Firebug(或类似)控制台api时访问行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆