Class to write log messages to console - Node.js Environment

Node.js examples for Environment:Log

Description

Class to write log messages to console

Demo Code

/**/*from   www .  j  ava2 s .c  om*/
 * Class to write log messages to console
 */
var logger = (function(){
   return {
       'log' : function(m){
           try{               
               var currentTime = new Date();
               var month = currentTime.getMonth() + 1;
               var day = currentTime.getDate();
               var year = currentTime.getFullYear();
               var hours = currentTime.getHours();
               var minutes = currentTime.getMinutes();
               var seconds = currentTime.getSeconds();

               var timestamp = month + "/" + day + "/" + year + ' ' + hours + ':' + minutes + ':' + seconds;               
               if(typeof(m) != 'object'){
                    console.log(timestamp + '   ' + m);
                }else{
                    console.log(timestamp);
                    console.log(m);
                }
           }catch(e){}    
       }
   } 
})();

Related Tutorials