日期:2014-05-16  浏览次数:20385 次

javascript logger blackbird jquery 改造

var logger=BizPlant.namespace("logger");
logger.config={
??? pattern:"%d{yyyy-MM-dd HH:mm:ss,SSS} %p [%t] %c{1}.%M()| line:%L | %m%n",
??? level:"info"
};
$(document).ready(function(){
??? var enabled=true;
??? var level={
??????? debug: true,
??????? info: true,
??????? warn: true,
??????? error: true,
??????? profile: true
??? };
??? var COOKIE_KEY="BizPlantLogger";
??? var classes = {};
??? var profiler = {};
??? var spans = [];
??? var cache = [];
??? var IDs = {
??????? blackbird: 'blackbird',
??????? checkbox: 'bbVis',
??????? filters: 'bbFilters',
??????? controls: 'bbControls',
??????? size: 'bbSize'
??? }
??? var state=(function(){
??????? var bizPlantLoggerValue=$.cookie(COOKIE_KEY);
??????? if(bizPlantLoggerValue!=null && bizPlantLoggerValue!=""){
??????????? return JSON.parse(bizPlantLoggerValue);
??????? }else{
??????????? return {
??????????????? pos:1,
??????????????? size:0,
??????????????? load:true
??????????? };
??????? }
??? })();
???
??? var recordState=function(){
??????? $.cookie(COOKIE_KEY,JSON.stringify(state));
??????? var newClass = [];
??????? for (var word in classes ) {
??????????? newClass.push( classes[ word ] );
??????? }
??????? $("#"+IDs.blackbird).removeClass().addClass(newClass.join( ' ' ));
??? };
??? var? reposition=function( position ) {
??????? if ( position === undefined || position == null ) {
??????????? position = ( state && state.pos === null ) ? 1 : ( state.pos + 1 ) % 4; //set to initial position ('topRight') or move to next position
??????? }
??? ???
??????? switch ( position ) {
??????????? case 0:
??????????????? classes[ 0 ] = 'bbTopLeft';
??????????????? break;
??????????? case 1:
??????????????? classes[ 0 ] = 'bbTopRight';
??????????????? break;
??????????? case 2:
??????????????? classes[ 0 ] = 'bbBottomLeft';
??????????????? break;
??????????? case 3:
??????????????? classes[ 0 ] = 'bbBottomRight';
??????????????? break;
??????? }
??????? state.pos = position;
??????? recordState();
??? }
??? var? resize=function( size ) {
??????? if ( size === undefined || size === null ) {
??????????? size = ( state && state.size == null ) ? 0 : ( state.size + 1 ) % 2;
??????? }
??????? classes[ 1 ] = ( size === 0 ) ? 'bbSmall' : 'bbLarge'
??????? var title=( size === 1 ) ? 'small' : 'large';
??????? $( "#"+IDs.size).attr("title",title).removeClass().addClass(title);
??????? state.size = size;
??????? recordState();
??? };
???
??? for ( type in level ) {
??????? spans.push( [ '<span class="', type, '" type="', type, '"></span>'].join( '' ) );
??? }
??? var inner = [
??? '<div class="header">',
??? '<div class="left">',
??? '<div id="', IDs.filters, '" class="filters" title="click to filter by message type">', spans.join( '' ), '</div>',
??? '</div>',
??? '<div class="right">',
??? '<div id="', IDs.controls, '" class="controls">',
??? '<span id="', IDs.size ,'" title="contract" op="resize"></span>',
??? '<span class="clear" title="clear" op="clear"></span>',
??? '<span class="close" title="close" op="close"></span>',
??? '</div>',
??? '</div>',
??? '</div>',
??? '<div class="main">',
??? '<div class="left"></div><div class="mainBody">',
??? '<ol>', cache.join( '' ), '</ol>',
??? '</div><div class="right"></div>',
??? '</div>',
??? '<div class="footer">',
??? '<div class="left"><label for="', IDs.checkbox, '"><input type="che