1

I'm using the console log to record any errors in a HTML/JS web application. Is there a way to output the contents of the console log?

For instance, lets say we log "Hello world" console.log('Hello world');

Is there a way I can get back what's been logged at a later time? Something like:

alert(console.log());

Thanks in advance!

3
  • You can overwrite the log method of the console object. console.log = function() { // store the logged data }, however you have only access to the manually logged data not those that are generated by browser. You may find this library useful, github.com/occ/TraceKit Commented Apr 18, 2014 at 3:42
  • Thanks @JAAulde. For later output, would you suggest storing all the logs in a single variable and appending to that variable each time an error is logged? Commented Apr 18, 2014 at 3:51
  • I'd push entries onto an array as I go Commented Apr 18, 2014 at 3:57

2 Answers 2

2

The console provides a log method which does nothing other than write your message into the console output in real time. You can see this in the developer tools of many browsers.

There is no way to ask the native console for a list of things logged. You would need to write something yourself, perhaps augmenting the native console.

Sign up to request clarification or add additional context in comments.

Comments

0

No, that is not possible.

Check this link for the full Console API Reference for Google Chrome. Other browsers have their own console API, but they're generally the same.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.