User tests: Successful: Unsuccessful:
Pull Request for Issue # .
This adds a defer
option to the formatted_text
logger. 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 defer
option, 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 defer
option. If php encounters a fatal error, the class' __destruct
function 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.
Configure a formatted_text
logger and include 'defer' => true
in its options array. A simple way to do this is to use the logging features of the Debug
plugin. There are two formatted_text
loggers 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.
If there is some documentation about using the formatted_text
logger, it should be updated to include this option. If there isn't any, there probably should be.
Discuss?
I'm using the class __destruct
function 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 that register_shutdown_function
is 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.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Labels |
Added:
?
|
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.
@okonomiyaki3000
Can you look at resolving the conflicts and poviding some unit tests so that this can be tested please.
Category | Libraries | ⇒ | Libraries Unit Tests |
I think it should be alright now.
Labels |
Added:
?
|
Rebased with the latest staging.
I have tested this item
# Testing Steps
I have tested this item
Tested successfully.
Log entries were created as expected with the defer option set to true.
Status | Pending | ⇒ | Ready to Commit |
Ready to Commit after two successful tests.
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-08-02 22:34:01 |
Closed_By | ⇒ | mbabker | |
Labels |
Added:
?
?
Removed: ? |
@okonomiyaki3000 please check: 5ace361 this should fix the most travis errors if not all. I have also marked the
__destruct()
nethod as public.