CodeIgniter Forums

Full Version: Getting output of log_message() to print on screen.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Posted this to SO, but you guys are way more helpful, so I'll try this here as well. Thanks!

I am writing some higher level integration testing scripts for a large application that I have written on CI-3. I basically provide parameters for each function and display the output for manual verification (usually a print_r style output for the returned object).

I make extensive use of 'debug' and 'info' logging as it dramatically reduces my debugging time, so I would like to show the log file with my raw function output so I can easily see if messages are as expected.

Is there anyway in CI to get the string output of the log_message() function?
Can I use some kind of buffer to grab the data being written to the log file?
Can I put a hook in there? can I override the function from my testing controller?
I was going to write my own wrapper on log_message() in a helper, like "whiteatoms_log_message()", to save the data to a variable and then call log_message(), but I'd rather leave my code exactly as I envision it going into prod after I cut the testing functions out.

The ugly option is to read the log file from the disk at script load and then again and completion and display the difference... but that seems like a terrible hack.

Thoughts?
The simplest thing I can think of would be to create a MY_Log class (extending CI_Log) which exposes a hook in the write_log() method (or whatever you want to do for debugging purposes) before calling parent::write_log().
(02-25-2015, 02:22 PM)mwhitney Wrote: [ -> ]The simplest thing I can think of would be to create a MY_Log class (extending CI_Log) which exposes a hook in the write_log() method (or whatever you want to do for debugging purposes) before calling parent::write_log().

Ahh ok, Still not that simple, but much less hacky.. thanks. This may be something that would be useful to add to the core, an ability to print the log when in a development environment.

Cheers,

whiteatom