Description:
When the agent/proxy is run on a production-suitable log level (often critical) it can be hard to see the root cause of a certain failure.
Most likely helpful information can be obtained from lower-level log messages which are not visible on the set log level, but that information is not accessible without a restart, and worse, it's sometimes impossible to recreate the failure condition.
How to repeat:
Track down a hard problem with the default log level ;)
Suggested fix:
Optionally save debug log information in a ringbuffer instead of discarding it.
Then when a critical message is logged, dump the entire output of the backlog buffer to the log file (or syslog) to aid troubleshooting.
This combines the best of two worlds: Normally the log file is empty as long as no error conditions are hit, but when one is encountered the file contains (hopefully) useful information, not only "something has gone terribly wrong".
The overhead should be neglible as long as we don't allow the buffer to grow too large (this can be implemented as both a byte-sized and a number of messages limit).