yii2: problem with the size of the log[yii2/log/FileTarget]
What steps will reproduce the problem?
The log is full and concurrent
What is the expected result?
The log should be full
What do you get instead?
some logs are too small
Additional info
Q | A |
---|---|
Yii version | 2.0.45 |
PHP version | 7.2.6 |
Operating system | windows |
same as #19079
hello, I’m back again, after our testing, The problem is due to rotateFiles and concurrency
config
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'categories' => ['open'],
'logVars' => [],
'maxFileSize' => 100, //for better display of errors
'maxLogFiles' => 5,
'logFile' => '@root/runtime/logs/open.log',
]
],
],
code
$request = Yii::$app->request;
$header = $request->getHeaders();
$get = $request->get();
$body = $request->bodyParams;
$method = $request->method;
Yii::info([
'header' => $header,
'get' => $get,
'body' => $body,
'method' => $method,
], 'open');
test with ab
ab -n1000 -c10 http://example.com/path1/path2
You will see that some logs are very small
By the way, I don’t think it’s a good idea to attach an application log when logvar is not empty, preferably something that can be controlled.
'logVars' => ['_GET', '_POST'],
// will hava
... category: application ....
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 33 (21 by maintainers)
Commits related to this issue
- Issue #19259 Fix locking during log file rotation and make rotateByCopy mandatory — committed to mikehaertl/yii2 by mikehaertl 2 years ago
- Fix #19259: Fix `yii\log\FileTarget` locking and always rotate files only by copy — committed to maxodrom/yii2 by mikehaertl 2 years ago
See the linked SO answer that I linked in my last comment above.
$would_block
is basically just a flag that indicates that something is seriously going wrong when accessing the lock file. This is not related to our problem.And we already use the default of blocking mode. That’s fine because we want a 2nd process to wait a (hopefully) short amount of time until the 1st process will release the lock.
LOCK_NB
is not what we want.