123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- define( [ "vwf/configuration" ], function( configuration ) {
- var TRACE = 1,
- DEBUG = 2,
- INFO = 3,
- WARN = 4,
- ERROR = 5,
- FATAL = 6;
- var exports = {
- levels: {
- trace: TRACE,
- debug: DEBUG,
- info: INFO,
- warn: WARN,
- error: ERROR,
-
- },
- label: undefined,
- context: undefined,
- level: WARN,
- for: function( label, context, level ) {
- return Object.create( this ).configure( label, context, level );
- },
- configure: function( label, context, level ) {
- var proto = Object.getPrototypeOf( this ) !== Object.prototype ?
- Object.getPrototypeOf( this ) : undefined;
- this.label = combined_label( proto && proto.label, label );
- this.context = context || proto && proto.context;
- this.level = { name: "warn", number: WARN };
- switch( level ) {
- case "trace": case "TRACE": this.level = { name: "trace", number: TRACE }; break;
- case "debug": case "DEBUG": this.level = { name: "debug", number: DEBUG }; break;
- case "info": case "INFO": this.level = { name: "info", number: INFO }; break;
- case "warn": case "WARN": this.level = { name: "warn", number: WARN }; break;
- case "error": case "ERROR": this.level = { name: "error", number: ERROR }; break;
-
- default: proto && delete this.level; break;
- }
- return this;
- },
-
- traceg: function( /* ... */ ) {
- TRACE >= this.level.number &&
- log.call( this, arguments, console && console.group, console );
- },
-
- debugg: function( /* ... */ ) {
- DEBUG >= this.level.number &&
- log.call( this, arguments, console && console.group, console );
- },
-
- infog: function( /* ... */ ) {
- INFO >= this.level.number &&
- log.call( this, arguments, console && console.group, console );
- },
-
- traceu: function() {
- TRACE >= this.level.number &&
- log.call( this, arguments, console && console.groupEnd, console );
- },
-
- debugu: function() {
- DEBUG >= this.level.number &&
- log.call( this, arguments, console && console.groupEnd, console );
- },
-
- infou: function() {
- INFO >= this.level.number &&
- log.call( this, arguments, console && console.groupEnd, console );
- },
-
- trace: function( /* ... */ ) {
- TRACE >= this.level.number &&
- log.call( this, arguments, console && console.debug, console );
- },
-
- debug: function( /* ... */ ) {
- DEBUG >= this.level.number &&
- log.call( this, arguments, console && console.debug, console );
- },
-
- info: function( /* ... */ ) {
- INFO >= this.level.number &&
- log.call( this, arguments, console && console.info, console );
- },
-
- warn: function( /* ... */ ) {
- WARN >= this.level.number &&
- log.call( this, arguments, console && console.warn, console );
- },
-
- error: function( /* ... */ ) {
- ERROR >= this.level.number &&
- log.call( this, arguments, console && console.error, console );
- },
-
- log: function( /* ... */ ) {
- log.call( this, arguments, console && console.log, console );
- },
-
-
-
-
- tracegx: function( /* label, ... */ ) {
- TRACE >= this.level.number &&
- log.call( this, arguments, console && console.group, console, true );
- },
-
-
- debuggx: function( /* label, ... */ ) {
- DEBUG >= this.level.number &&
- log.call( this, arguments, console && console.group, console, true );
- },
-
-
- infogx: function( /* label, ... */ ) {
- INFO >= this.level.number &&
- log.call( this, arguments, console && console.group, console, true );
- },
-
- tracex: function( /* ... */ ) {
- TRACE >= this.level.number &&
- log.call( this, arguments, console && console.debug, console, true );
- },
-
- debugx: function( /* label, ... */ ) {
- DEBUG >= this.level.number &&
- log.call( this, arguments, console && console.debug, console, true );
- },
-
- infox: function( /* label, ... */ ) {
- INFO >= this.level.number &&
- log.call( this, arguments, console && console.info, console, true );
- },
-
- warnx: function( /* label, ... */ ) {
- WARN >= this.level.number &&
- log.call( this, arguments, console && console.warn, console, true );
- },
-
- errorx: function( /* label, ... */ ) {
- ERROR >= this.level.number &&
- log.call( this, arguments, console && console.warn, console, true );
- },
-
- logx: function( /* label, ... */ ) {
- log.call( this, arguments, console && console.log, console, true );
- },
- };
-
-
-
-
-
-
-
-
-
-
-
- function log( args, appender, context, extra ) {
-
-
- if ( args = normalize.call( this, args, extra ) ) {
- appender && appender.apply( context, args );
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- function normalize( args, extra ) {
-
-
- if ( extra && ( typeof args[0] == "string" || args[0] instanceof String ) ) {
- var label = args[0];
- var start = 1;
- } else {
- var label = undefined;
- var start = 0;
- }
-
-
- if ( typeof args[ start ] == "function" || args[ start ] instanceof Function ) {
-
-
- args = args[ start ].call( args[ start+1 ] || this.context, this.level.name, this.level.number );
-
-
- if ( args !== undefined && ( typeof args != "object" || ! ( args instanceof Array ) ) ) {
- args = [ args ];
- }
- } else {
-
- if ( start > 0 ) {
- args = Array.prototype.slice.call( args, start );
- }
- }
-
-
- return args ? prefixed_arguments( this.label, label, args ) : undefined;
- }
-
- function prefixed_arguments( label, extra, args ) {
- if ( label || extra ) {
- if ( args.length == 0 ) {
- return [ combined_label( label, extra ) ];
- } else if ( typeof args[0] == "string" || args[0] instanceof String ) {
- return [ combined_label( label, extra ) + ": " + args[0] ].concat( Array.prototype.slice.call( args, 1 ) );
- } else {
- return [ combined_label( label, extra ) + ":" ].concat( args );
- }
- } else {
- return args;
- }
- }
-
- function combined_label( label, extra ) {
-
- var separator = extra && extra.match( /^[0-9A-Za-z]/ ) ? "." : "";
-
- if ( label && extra ) {
- return label + separator + extra;
- } else if ( extra ) {
- return extra;
- } else if ( label ) {
- return label;
- } else {
- return undefined;
- }
- }
-
-
-
- exports.configure( undefined, undefined, configuration.active["log-level"] || "warn" );
- configuration.changed( function( active ) {
- exports.configure( undefined, undefined, active["log-level"] || "warn" );
- }, this );
-
- return exports;
- } );
|