Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nodejs console.log timestampt

var log = console.log;

console.log = function () {
    var first_parameter = arguments[0];
    var other_parameters = Array.prototype.slice.call(arguments, 1);

    function formatConsoleDate (date) {
        var hour = date.getHours();
        var minutes = date.getMinutes();
        var seconds = date.getSeconds();
        var milliseconds = date.getMilliseconds();

        return '[' +
               ((hour < 10) ? '0' + hour: hour) +
               ':' +
               ((minutes < 10) ? '0' + minutes: minutes) +
               ':' +
               ((seconds < 10) ? '0' + seconds: seconds) +
               '.' +
               ('00' + milliseconds).slice(-3) +
               '] ';
    }

    log.apply(console, [formatConsoleDate(new Date()) + first_parameter].concat(other_parameters));
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: node js cross origin error 
Javascript :: mongoose reset database 
Javascript :: set node_env 
Javascript :: convert queryset to json django 
Javascript :: binary search algorithm in javascript 
Javascript :: loop elements in javascript 
Javascript :: set auth header on axios instance 
Javascript :: javascript enable clipboard 
Javascript :: ubuntu 18.04 nodejs insatll 
Javascript :: bootstrap datepicker mindate today 
Javascript :: javascript replace last occurrence of a letter 
Javascript :: Uncaught TypeError: Object prototype may only be an Object or null: undefined 
Javascript :: convert date to string javascript 
Javascript :: javascript get 1 hour from now 
Javascript :: count array filter javascript 
Javascript :: deep merge nested objects javascript 
Javascript :: how to get number of a specific element of an array 
Javascript :: remove backslash from string 
Javascript :: angularjs round to 2 decimal places input 
Javascript :: random number in javascript between two numbers 
Javascript :: react join array of components 
Javascript :: ifsc code yup validation 
Javascript :: expressjs async await 
Javascript :: ruby write json to file 
Javascript :: array_diff in jquery 
Javascript :: multiply function javascript 
Javascript :: React count up on scroll 
Javascript :: get home dir in nodejs 
Javascript :: reload a child component in angular 
Javascript :: react js date ago 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =