-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interleaved log records using StreamHandler #1552
Comments
Minimal reproducible exampleindex.php <?php
require_once(__DIR__ . '/vendor/autoload.php');
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
$logger = new Logger('channel-name');
$logger->pushHandler(new StreamHandler(__DIR__ . '/app.log'));
$logger->info('This is a log!' . str_repeat('.', 8192)); Run it once > php index.php
> wc --max-line-length app.log
8266 app.log Run it in parallel (output shortened) > parallel php index.php ::: {1..1000}
> wc --lines --max-line-length app.log
1000 16458 app.log
> grep -A1 "INFO.*INFO" app.log
[2021-05-07T11:01:21.395883+02:00] channel-name.INFO: This is a log!.....[2021-05-07T11:01:21.395883+02:00] channel-name.INFO: This is a log!..... [] []
............ [] [] |
Seldaek
added a commit
that referenced
this issue
May 28, 2021
Set StreamHandler stream chunk size, fixes #1552
robocoder
pushed a commit
to robocoder/monolog
that referenced
this issue
May 24, 2022
This ensures atomic log record writing to the output stream.
Seldaek
pushed a commit
that referenced
this issue
Jun 9, 2022
This ensures atomic log record writing to the output stream.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Monolog version 1.24.0
PHP version 7.0.33
We get interleaved log records while using
StreamHandler
. The under-laying PHP stream writer implements a chunked write with a default chunk size of 8192 bytes. In an application with many concurrent processes writing to a single log file this leads to interleaved log records.Example (if the chunk size would be 4):
This issue could be fix in a simular way as in #1129 by calling
stream_set_chunk_size
.The text was updated successfully, but these errors were encountered: