1 /*
  2  *  Copyright 2010 Scriptoid s.r.l
  3  */
  4 
  5 /**no debug at all*/
  6 var LOG_LEVEL_NONE  = 0;
  7 
  8 /**show only errors*/
  9 var LOG_LEVEL_ERROR = 1;
 10 
 11 /**show all up to (and including) info
 12  *Setting the log level at info level will slow your browser a lot....so use it carefully
 13  **/
 14 var LOG_LEVEL_INFO  = 2;
 15 
 16 /**show even the debug messages*/
 17 var LOG_LEVEL_DEBUG = 3;
 18 
 19 
 20 
 21 
 22 /**
 23  * A singleton object used to log all messages in Diagramo.
 24  * It will adjust to any know (by us) browser and try to behave nice :)
 25  * 
 26  * This acts like a wrapper to Firebug
 27  * as if you do not have Firebug installed (or no FF used)
 28  * the application crashes due to the fact that 'console'
 29  * object is not present.
 30  * 
 31  * 
 32  * @constructor
 33  * @this {Log}
 34  * @see For IE9  <a href="http://msdn.microsoft.com/en-us/library/dd565625%28v=vs.85%29.aspx#consolelogging">http://msdn.microsoft.com/en-us/library/dd565625%28v=vs.85%29.aspx#consolelogging</a>
 35  **/
 36 var Log  = {
 37     /**It will keep the log level (anything above this level will be printed)*/
 38     level : LOG_LEVEL_ERROR,
 39     
 40     /**
 41     * The less important of all messages
 42     * @param {String} message - the message to be logged
 43     **/
 44     debug: function (message){
 45         if(typeof console != 'undefined'){
 46             if(this.level >= LOG_LEVEL_DEBUG){
 47                 //TODO: in IE is log
 48                 //in FF is debug
 49                 //console.debug(message);
 50             }
 51         }
 52     },
 53 
 54 
 55     /**
 56     * The commonly used log message
 57     * @param {String} message - the message to be logged
 58     **/
 59     info : function (message){
 60         if(typeof console != 'undefined'){
 61             if(this.level >= LOG_LEVEL_INFO){
 62                 console.info(message);
 63             }
 64         }
 65     },
 66 
 67     /**
 68     * The worse kind of message. Usually a crash
 69     * @param {String} message - the message to be logged
 70     **/
 71     error : function (message){
 72         if(typeof console != 'undefined'){
 73             if(this.level >= LOG_LEVEL_ERROR){
 74                 console.error(message);
 75             }
 76         }
 77     },
 78 
 79     /**
 80      *Start grouping the log messages
 81      *@param {String} title - the title of the group
 82      *@see <a href="http://getfirebug.com/logging">http://getfirebug.com/logging</a>
 83      **/
 84     group : function(title){
 85         if(typeof console != 'undefined'){
 86             if(this.level >= LOG_LEVEL_ERROR){
 87                 /**If we do not test for group() function you will get an error in Opera
 88                  *as Opera has it's own console...which does not have a group() function*/
 89                 if(typeof console.group == 'function'){
 90                     console.group(title);
 91                 }
 92             }
 93         }
 94     },
 95 
 96     /**Ends current message grouping*/
 97     groupEnd : function(){
 98         if(typeof console != 'undefined'){
 99             if(this.level >= LOG_LEVEL_ERROR){
100                 /**If we do not test for groupEnd() function you will get an error in Opera
101                  *as Opera has it's own console...which does not have a group() function*/
102                 if(typeof console.groupEnd == 'function'){
103                     console.groupEnd();
104                 }
105             }
106         }
107     }
108 
109 }
110 
111 /*Set the log level*/
112 Log.level = LOG_LEVEL_INFO; 
113 //Log.level = LOG_LEVEL_ERROR;
114 //Log.level = LOG_LEVEL_NONE;
115 
116