Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this:</p> <pre><code>console.logCopy = console.log.bind(console); console.log = function(data) { var currentDate = '[' + new Date().toUTCString() + '] '; this.logCopy(currentDate, data); }; </code></pre> <p><br><br> Or this, in case you want a timestamp:</p> <pre><code>console.logCopy = console.log.bind(console); console.log = function(data) { var timestamp = '[' + Date.now() + '] '; this.logCopy(timestamp, data); }; </code></pre> <p><br><br> To log <strong>more than one thing</strong> <em>and</em> in a nice way (like object tree representation):</p> <pre><code>console.logCopy = console.log.bind(console); console.log = function() { if (arguments.length) { var timestamp = '[' + Date.now() + '] '; this.logCopy(timestamp, arguments); } }; </code></pre> <p><br><br> <strong>With format string</strong> (<a href="http://jsfiddle.net/yTfSy/" rel="noreferrer">JSFiddle</a>)</p> <pre><code>console.logCopy = console.log.bind(console); console.log = function() { // Timestamp to prepend var timestamp = new Date().toJSON(); if (arguments.length) { // True array copy so we can call .splice() var args = Array.prototype.slice.call(arguments, 0); // If there is a format string then... it must // be a string if (typeof arguments[0] === "string") { // Prepend timestamp to the (possibly format) string args[0] = "%o: " + arguments[0]; // Insert the timestamp where it has to be args.splice(1, 0, timestamp); // Log the whole array this.logCopy.apply(this, args); } else { // "Normal" log this.logCopy(timestamp, args); } } }; </code></pre> <p><br></p> <p>Outputs with that:</p> <p><img src="https://i.stack.imgur.com/JY8Uf.png" alt="Sample output"></p> <p>P.S.: Tested in Chrome only.</p> <p>P.P.S.: <code>Array.prototype.slice</code> is not perfect here for it would be logged as an array of objects rather than a series those of.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload