1、执行命令,报错:PHP Warning: strpos(): Empty needle in E:\wwwroot\pcs-api\vendor\yiisoft\yii2\log\Target.php on line 243,如图1
图1PS E:\wwwroot\pcs-api> ./yii cmc-console-user/sync
Exception 'yii\web\ServerErrorHttpException' with message 'Framework Service Console HTTP request failed: 租户信息不存在
'
in E:\wwwroot\pcs-api\common\services\CmcConsoleUserService.php:102
Stack trace:
#0 E:\wwwroot\pcs-api\console\controllers\CmcConsoleUserController.php(62): common\services\CmcConsoleUserService::httpG
etUserList(Array)
#1 [internal function]: console\controllers\CmcConsoleUserController->actionSync()
#2 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#3 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#4 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\console\Controller.php(148): yii\base\Controller->runAction('sync', Array)
#5 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\base\Module.php(528): yii\console\Controller->runAction('sync', Array)
#6 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('cmc-console-use...',
Array)
#7 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('cmc-console-
use...', Array)
#8 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\base\Application.php(386): yii\console\Application->handleRequest(Object(yii\c
onsole\Request))
#9 E:\wwwroot\pcs-api\yii(23): yii\base\Application->run()
#10 {main}
PHP Warning: strpos(): Empty needle in E:\wwwroot\pcs-api\vendor\yiisoft\yii2\log\Target.php on line 243
PHP Warning: strpos(): Empty needle in E:\wwwroot\pcs-api\vendor\yiisoft\yii2\log\Target.php on line 243
PHP Warning: strpos(): Empty needle in E:\wwwroot\pcs-api\vendor\yiisoft\yii2\log\Target.php on line 243
PHP Warning: strpos(): Empty needle in E:\wwwroot\pcs-api\vendor\yiisoft\yii2\log\Target.php on line 243
2、查看 \console\runtime\logs\app.log
2019-04-02 14:03:05 [-][-][-][warning][yii\log\Dispatcher::dispatch] Unable to send log via yii\log\DbTarget: PHP Warning 'yii\base\ErrorException' with message 'strpos(): Empty needle'
in E:\wwwroot\pcs-api\vendor\yiisoft\yii2\log\Target.php:243
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError(2, 'strpos(): Empty...', 'E:\\wwwroot\\pcs-...', 243, Array)
#1 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\log\Target.php(243): strpos('yii\\base\\Applic...', '')
#2 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\log\Target.php(124): yii\log\Target::filterMessages(Array, 0, Array, Array)
#3 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\log\Dispatcher.php(189): yii\log\Target->collect(Array, false)
#4 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\log\Logger.php(177): yii\log\Dispatcher->dispatch(Array, false)
#5 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\log\Logger.php(124): yii\log\Logger->flush()
#6 [internal function]: yii\log\Logger->yii\log\{closure}()
#7 {main}
2019-04-02 14:03:05 [-][-][-][info][application] $_GET = []
$_POST = []
$_FILES = []
$_COOKIE = []
$_SERVER = []
3、在命令行中编辑
var_dump(strpos("Fabio", 'b'));
exit;
PS E:\wwwroot\pcs-api> ./yii cmc-console-user/sync
int(2)
4、在命令行中编辑,在控制台命令行中一旦抛出异常,写入日志时,就会报错:PHP Warning: strpos(): Empty needle,如图2
图2var_dump(strpos("Fabio", ''));
exit;
PS E:\wwwroot\pcs-api> ./yii cmc-console-user/sync
PHP Warning 'yii\base\ErrorException' with message 'strpos(): Empty needle'
in E:\wwwroot\pcs-api\console\controllers\CmcConsoleUserController.php:37
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError(2, 'strpos(): Empty...', 'E:\\wwwroot\\pcs-...', 37, Array)
#1 E:\wwwroot\pcs-api\console\controllers\CmcConsoleUserController.php(37): strpos('Fabio', '')
#2 [internal function]: console\controllers\CmcConsoleUserController->actionSync()
#3 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#4 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#5 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\console\Controller.php(148): yii\base\Controller->runAction('sync', Array)
#6 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\base\Module.php(528): yii\console\Controller->runAction('sync', Array)
#7 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('cmc-console-use...',
Array)
#8 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('cmc-console-
use...', Array)
#9 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\base\Application.php(386): yii\console\Application->handleRequest(Object(yii\c
onsole\Request))
#10 E:\wwwroot\pcs-api\yii(23): yii\base\Application->run()
#11 {main}
PHP Warning: strpos(): Empty needle in E:\wwwroot\pcs-api\vendor\yiisoft\yii2\log\Target.php on line 243
PHP Warning: strpos(): Empty needle in E:\wwwroot\pcs-api\vendor\yiisoft\yii2\log\Target.php on line 243
PHP Warning: strpos(): Empty needle in E:\wwwroot\pcs-api\vendor\yiisoft\yii2\log\Target.php on line 243
PHP Warning: strpos(): Empty needle in E:\wwwroot\pcs-api\vendor\yiisoft\yii2\log\Target.php on line 243
5、编辑 \console\config\main.php,调整日志组件的配置
'components' => [
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
'file' => [
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
'db' => [
'class' => 'yii\log\DbTarget',
'except' => ['*'],
'prefix' => function () {
$url = !Yii::$app->request->isConsoleRequest ? Yii::$app->request->getUrl() : null;
$user = Yii::$app->has('user', true) ? Yii::$app->get('user') : null;
$userId = $user ? $user->getId(false) : '-';
return sprintf('[%s][%s][%s]', Yii::$app->id, $url, $userId);
},
'logVars' => [],
]
],
],
],
调整为:
'components' => [
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
'file' => [
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
'db' => [
'class' => 'yii\log\DbTarget',
'levels' => ['error', 'warning'],
],
],
],
],
6、在控制台命令行中一旦抛出异常,写入日志时,报错:PHP Warning: strpos(): Empty needle 的问题已经得到解决
PS E:\wwwroot\pcs-api> ./yii cmc-console-user/sync
PHP Warning 'yii\base\ErrorException' with message 'strpos(): Empty needle'
in E:\wwwroot\pcs-api\console\controllers\CmcConsoleUserController.php:37
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError(2, 'strpos(): Empty...', 'E:\\wwwroot\\pcs-...', 37, Array)
#1 E:\wwwroot\pcs-api\console\controllers\CmcConsoleUserController.php(37): strpos('Fabio', '')
#2 [internal function]: console\controllers\CmcConsoleUserController->actionSync()
#3 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#4 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#5 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\console\Controller.php(148): yii\base\Controller->runAction('sync', Array)
#6 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\base\Module.php(528): yii\console\Controller->runAction('sync', Array)
#7 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('cmc-console-use...',
Array)
#8 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('cmc-console-
use...', Array)
#9 E:\wwwroot\pcs-api\vendor\yiisoft\yii2\base\Application.php(386): yii\console\Application->handleRequest(Object(yii\c
onsole\Request))
#10 E:\wwwroot\pcs-api\yii(23): yii\base\Application->run()
#11 {main}