+ -
当前位置:首页 → 问答吧 → 使用blackbirdjs调试js

使用blackbirdjs调试js

时间:2009-12-30

来源:互联网

  使用blackbirdjs有段时间了,觉得相当的简单好用,官网的说明也很详细,在这里我就介绍一下它,主要是翻译官网的一些东东,大家不要拍砖哈。
1.    介绍
blackbirdjs类似于log4j,用来在js记录日志。主页为http://digitalbush.com/projects/masked-input-plugin/。
2.    需要文件
导入blackbird.css和blackbird.js,其中css需要用到blackbird_icons.png和blackbird_panel.png。
3.    API
log.toggle()
Hide/show Blackbird(隐藏/显示面板)
log.move()
Move Blackbird to next fixed positions: top-left, top-right, bottom-left, bottom-right(移动面板,位置为四个角)
log.resize()
Expand/contract Blackbird (伸展/收缩面板)
log.clear()
Clear all contents of Blackbird(清除面板)
log.debug( message )
Add a debug message to Blackbird(增加debug信息)
message: the string content of the debug message
log.info( message )
Add an info message to Blackbird(增加info信息)
message: the string content of the info message
log.warn( message )
Add a warning message to Blackbird(增加warn信息)
message: the string content of the warn message
log.error( message )
Add an error message to Blackbird(增加error信息)
message: the string content of the warn message
log.profile( label )
Start/end a time profiler for Blackbird. If a profiler named string does not exist, create a new profiler. Otherwise, stop the profiler string and display the time elapsed (in ms).这个我认为是一个可以记录运行时间的标识,当调用此方法时,如果没有label指定的标识,则以这个label为key开始一个标识,如果有则停止这个标识。
label: the string identifying a specific profile timer
4.    快捷键
blackbirdjs的快捷键都是在js的readkey方法中定义的,如果要屏蔽或者修改的话,就在方法内修改。
F2:隐藏/显示面板
Shift+F2:移动面板
Alt+Shift+F2:清除面板
5.    控制面板说明
面板中显示的就是log信息,其中左边的按钮是过滤不同级别的日志(图标上有提示,就不细说了)如果按住alt键点击图标,则是单独显示出此级别信息(过滤其它级别),如果不按住alt,则是在显示/隐藏此级别信息中切换(不影响其它级别),alt功能在firefox中无效,因为alt后焦点就到菜单上去了,没发触发点击事件。右边分别是伸缩、清除和关闭三个按钮。
6.    定制
1)    Blackbird.js通过var NAMESPACE = 'log'来指定了日志对象名,如果log跟其它脚本有冲突的话,可以定义其它名称,如var NAMESPACE = 'blackbird',引用的时候就是用blackbird.debug(message);
2)    改变默认行为
可以使用如下代码来改变默认行为:
var log = {
          toggle: function() {},
          move: function() {},
          resize: function() {},
          clear: function() {},
          debug: function() {},
          info: function() {},
          warn: function() {},
          error: function() {},
          profile: function() {}
    };
7.    注意事项
如果要上线,应屏蔽log的快捷键,具体方法见第四点。

作者: chris_strive   发布时间: 2009-12-30

相关阅读 更多