Add an option to defer writing logs.#13692
Conversation
|
@okonomiyaki3000 please check: 5ace361 this should fix the most travis errors if not all. I have also marked the |
|
@zero-24 Thanks for that! My tabs were wrong? That's so weird... |
Yes it looks like your code uses 4 spaces and not tabs 😄 |
|
I better check my settings. I'm definitely not trying make a statement about that. |
|
I suggest that you add some unit tests in the file https://github.com/joomla/joomla-cms/blob/staging/tests/unit/suites/libraries/joomla/log/loggers/JLogLoggerFormattedTextTest.php as well. With your text instructions it is rather hard to test this PR. |
|
@laoneo Good idea. |
|
@okonomiyaki3000 |
6383952 to
bcecda4
Compare
|
I think it should be alright now. |
JLogEntry -> LogEntry JFile -> \JFile
bcecda4 to
26fe1b0
Compare
|
Rebased with the latest staging. |
|
I have tested this item ✅ successfully on 26fe1b0
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13692. |
|
I have tested this item ✅ successfully on 26fe1b0 Log entries were created as expected with the defer option set to true. This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13692. |
|
Ready to Commit after two successful tests. |

Pull Request for Issue # .
Summary of Changes
This adds a
deferoption to theformatted_textlogger. The option is not enabled by default so the logger will continue to function in the usual way unless specifically configured.The normal way for this logger to function is to format each received log entry as a line of text and write it to a file as it is received.
When using the
deferoption, received log entries will just be stored in an array when received. It will not be until the logger is destroyed (basically this happens in the shutdown process, so after the response has been sent) that the stored entries are formatted as lines of text and all written to the log file at once. This may be better for performance since multiple write operations are combined as one and (more importantly) not performed until the response has already been sent.There is a small caveat which should be considered when deciding whether or not to use the
deferoption. If php encounters a fatal error, the class'__destructfunction may never be called and all unwritten logs will be lost. If you are writing logs to help you determine why your fatal errors are happening, this option is not for you.Testing Instructions
Configure a
formatted_textlogger and include'defer' => truein its options array. A simple way to do this is to use the logging features of theDebugplugin. There are twoformatted_textloggers already configured in that plugin (must be activated in the plugin settings) so you only need to make a minor modification to their options arrays.Documentation Changes Required
If there is some documentation about using the
formatted_textlogger, it should be updated to include this option. If there isn't any, there probably should be.Discuss?
I'm using the class
__destructfunction to trigger the writing of deferred logs. It's pretty convenient and it works because we can rely on the logger instance not being destroyed until the program shuts down. However, it's possible thatregister_shutdown_functionis a better choice. I haven't tested it or even thought about it much so, if anyone has any thoughts about it, please let me know.