title: Add dynamic values to the console methods at run-time with preservation of original call position and line number intact
body: <p>I made the following class to 'hijack' the <code>console.log</code> function. The reason behind this is that I want to add and remove values
  <strong>dynamically</strong>. It will be used for debug purposes, so the <strong>origin of the function call</strong> <code>console.log()</code> is important. In the following code I will explain my logic in the comments.</p>
  
  <pre><code>export class ConsoleLog {
    private _isActive = false;
    private _nativeLogFn: any;
  
    constructor() {
  
      // ----------------------
      // Store the native console.log function, so it can be restored later 
      // ----------------------
  
      this._nativeLogFn = console.log;
  
    }
  
    public start() {
      if (!this._isActive) {
  
        // ----------------------
        // Create a new function as replacement for the native console.log 
        // function. *** This will be the subject of my question ***
        // ----------------------
  
        console.log = console.log.bind(console, Math.random());
  
        this._isActive = true;
      }
    }
  
    public stop() {
      if (this._isActive) {
        // Restore to native function
        console.log = this._nativeLogFn;
        this._isActive = false;
      }
    }
  }
  </code></pre>
  
  <p>The problem with this setup is, that the new function is assigned in a static form.</p>
  
  <pre><code>// Function random() generates a number at the moment I assign the function. 
  // Let's say it's the number *99* for example sake. 
  
  console.log.bind(console, Math.random());
  </code></pre>
  
  <p>Every time the <code>console.log(...)</code> is called, it will output <em>99</em>. So it's pretty much static. (To be ahead of you: no my goal isn't outputting a random number, lol, but I just use it to test if the output is dynamic or not.). </p>
  
  <p>The annoying part is, using the function with the
  <code>console.log.bind</code> is the only way I found that actually preserves the 
  origin caller and line number.</p>
  
  <p>I wrote the following simple test. </p>
  
  <pre><code>    console.log('Before call, active?', 'no'); // native log
  
      obj.start();  // Calls start and replaces the console.log function
  
      console.log('foo'); // This will output 'our' 99 to the console.
      console.log('bar'); // This will output 'our' 99 again.
  
      obj.stop(); // Here we restore the native console.log function
  
      console.log('stop called, not active'); // native log again
  
      // Now if I call it again, the random number has changed. What is 
      // logical, because I re-assign the function.
  
      obj.start();  // Calls start and replaces the console.log function
      console.log('foo'); // This will output N to the console.
      // But then I have to call start/log/stop all the time. 
  </code></pre>
  
  <p><strong>Question</strong>: How can I add values to the console.log at run time without losing the origin caller filename and line number... AND without bothering the library consumer once this class is initiated with start().</p>
  
  <blockquote>
    <p><strong>EDIT:</strong> Added a plkr: <a href="https://embed.plnkr.co/Zgrz1dRhSnu6OCEUmYN0" rel="noreferrer">https://embed.plnkr.co/Zgrz1dRhSnu6OCEUmYN0</a></p>
  </blockquote>