Browser Console Logging
This issue doesn't really belong in this repo, but I'm writing some thoughts for later in the broader ecosystem.
Currently, in ACPAN, I have things set up to send Monolog logs to the browser console. Monolog does this by (somewhat magically) appending a script tag to the end of the response body, which contains what you'd expect (a bunch of console.log() calls).
That works pretty great, except the most interesting requests are POSTs that typically receive a 301/302 redirect response. Which means devs don't get those logs.
Some ideas for later:
-
Use a special RedirectResponse that does the usual RedirectResponse thing in production, but in dev-mode (or if there's a cookie, or something) sends a response with a response body containing a short message and link to the URL. And (or?) some javascript that navigates to the redirection page immediately or nearly immediately. Ideally, this response would have a less-common 3xx status code (300? 303?), if one exists that will work with common browsers. Failing that, some 2xx response could be okay.
-
Write our own extension that works kind of like FirePHP or whatever. Seems like a lot of work.
-
Have some temporary log-cache on the server and a bit of javascript that GETs it and writes to the console. Figuring out how to properly clear that cache and stuff is probably a pain.
I think the first solution is probably the way to go. Come to think of it, we could ship a middleware that transforms the response. That way application code wouldn't have to know anything about it. One the way back out through the pipeline, we could just replace any 301/302 responses with a new one.