Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 4
    I got it working by using div_log.textContent += text; Commented Oct 17, 2015 at 15:53
  • Adding console.error = console.log = (function... made mine work for errors. This could work for other console.[whatever] as well. Also @srgsanky's change was required for it to work on mine. Commented Feb 2, 2017 at 0:26
  • Yeah textContent definitely looks like it is the right attribute to use today. Justin - when you override a browser API, usually you want to store a reference to and call the API, so your new function that you assign should still be calling the old console.error or console.log function. I don't think that can be done if you set multiple attrs with one function - will need multiple functions. Commented Dec 29, 2017 at 21:43
  • this works! but by using div_log.innerHTML += text + '<br />'; will be more clear Commented Mar 29, 2019 at 7:29
  • what do you mean old console . I don't get multiple console in single function . your code same as pinned answer . if (typeof console !== 'undefined') { if (typeof console.log !== 'undefined') { console.log = (function (old_function) { return function (text) { old_function(text); const newMessage = text.replace('%c', ''); setMessage([...message, newMessage]); }; })(console.log.bind(console)); } Commented Apr 4, 2023 at 10:53