When writing large logs to a non-blocking stream, logs are often truncated. The exact length of the line that is actually written varies between calls.
Here's a snippet that attempts to write around 1M characters to a non-blocking stream:
stream_set_blocking(STDOUT, false);
$log = new Logger("log", [new StreamHandler(STDOUT)]);
$log->info(join(",", array_fill(0, 100000, "123456789"))); // ~1MB
Run with php snippet.php | wc -c to see the number of characters actually written. On my platform, this is typically around 64K. I'm using monolog version 3.9.0.
The problem lies in the StreamHandler::streamWrite() method, which ignores the return value of fwrite(). I believe the correct solution is to call fwrite() in a loop until all characters are written. If it is desirable to have this behavior in monolog, I am willing to put together a patch.
When writing large logs to a non-blocking stream, logs are often truncated. The exact length of the line that is actually written varies between calls.
Here's a snippet that attempts to write around 1M characters to a non-blocking stream:
Run with
php snippet.php | wc -cto see the number of characters actually written. On my platform, this is typically around 64K. I'm using monolog version 3.9.0.The problem lies in the
StreamHandler::streamWrite()method, which ignores the return value offwrite(). I believe the correct solution is to callfwrite()in a loop until all characters are written. If it is desirable to have this behavior in monolog, I am willing to put together a patch.