소스 검색

1. 关闭不必要的日志上下文变量(默认日志会记录 $_GET, $_POST, $_SESSION 等,这些可以通过配置文件中的 logVars 控制)
2. 关闭数据库查询日志
'components' => [
'db' => [
'enableLogging' => false, // 关闭 SQL 日志
'enableProfiling' => false, // 关闭 SQL 性能分析
],
]
3. 日志记录级别统一为:
'log' => [
'targets' => [
[
'levels' => ['error', 'warning', 'info']
]
4. 线上不加载模块:gii 与 debug

shizhongqi 11 달 전
부모
커밋
c43b485d80
8개의 변경된 파일38개의 추가작업 그리고 20개의 파일을 삭제
  1. 3 1
      app-ghs/config/main.php
  2. 3 1
      app-hd/config/main.php
  3. 3 1
      app-mall/config/main.php
  4. 3 1
      app-pt/config/main.php
  5. 2 0
      common/components/IntraCityExpress.php
  6. 18 14
      common/config/main-local.php
  7. 5 1
      common/config/main.php
  8. 1 1
      env.php

+ 3 - 1
app-ghs/config/main.php

@@ -27,7 +27,9 @@ return [
 			'targets' => [
 				[
 					'class' => 'yii\log\FileTarget',
-					'levels' => ['error', 'warning'],
+					'levels' => ['error', 'warning', 'info'], // 需要查看调用链,加入 'trace'
+                    // 决定了日志记录时会额外保存哪些 PHP 超全局变量
+                    'logVars' => [], // ['_GET', '_POST', '_FILES', '_SESSION']
 				],
 			],
 		],

+ 3 - 1
app-hd/config/main.php

@@ -27,7 +27,9 @@ return [
 			'targets' => [
 				[
 					'class' => 'yii\log\FileTarget',
-					'levels' => ['error', 'warning', 'info', 'trace'], // 修改日志文件会记录的级别
+					'levels' => ['error', 'warning', 'info'], // 修改日志文件会记录的级别 -- 需要查看调用链,加入 'trace'
+					// 决定了日志记录时会额外保存哪些 PHP 超全局变量
+                    'logVars' => [], // ['_GET', '_POST', '_FILES']
 				],
 			],
 		],

+ 3 - 1
app-mall/config/main.php

@@ -26,7 +26,9 @@ return [
             'targets' => [
                 [
                     'class' => 'yii\log\FileTarget',
-                    'levels' => ['error', 'warning'],
+                    'levels' => ['error', 'warning', 'info'], // 需要查看调用链,加入 'trace'
+                    // 决定了日志记录时会额外保存哪些 PHP 超全局变量
+                    'logVars' => [], // ['_GET', '_POST', '_FILES', '_SESSION']
                 ],
             ],
         ],

+ 3 - 1
app-pt/config/main.php

@@ -27,7 +27,9 @@ return [
 			'targets' => [
 				[
 					'class' => 'yii\log\FileTarget',
-					'levels' => ['error', 'warning'],
+					'levels' =>  ['error', 'warning', 'info'], // 需要查看调用链,加入 'trace'
+                    // 决定了日志记录时会额外保存哪些 PHP 超全局变量
+                    'logVars' => [], // ['_GET', '_POST', '_FILES', '_SESSION']
 				],
 			],
 		],

+ 2 - 0
common/components/IntraCityExpress.php

@@ -3,6 +3,7 @@
 namespace common\components;
 
 use hd\models\IntraCity\StoreFeeForm;
+use Yii;
 use yii\helpers\Json;
 //use linslin\yii2\curl;
 use bizHd\wx\classes\WxOpenClass;
@@ -125,6 +126,7 @@ class IntraCityExpress
             $result = $wxApi->request($url, $data);
             return $result;
         } catch (\Exception $e) {
+            Yii::error($e->getMessage());
             // 如果WxApi方式失败,回退到简单方式
             util::fail('error');
         }

+ 18 - 14
common/config/main-local.php

@@ -1,16 +1,20 @@
 <?php
-$config = [
-	'bootstrap' => ['debug', 'gii'],
-	'modules' => [
-		'debug' => [
-			'class' => 'yii\debug\Module',
-			'allowedIPs' => [getenv('DEBUG_ALLOWED_IP','127.0.0.1')],
-		],
-		'gii' => [
-			'class' => 'yii\gii\Module',
-			'allowedIPs' => [getenv('GII_ALLOWED_IP','127.0.0.1')],
-		],
-	],
-	
-];
+// 线上
+if (getenv('YII_ENV') == 'production') {
+    $config = [];
+} else { // 非线上
+    $config = [
+        'bootstrap' => ['debug', 'gii'],
+        'modules' => [
+            'debug' => [
+                'class' => 'yii\debug\Module',
+                'allowedIPs' => [getenv('DEBUG_ALLOWED_IP','127.0.0.1')],
+            ],
+            'gii' => [
+                'class' => 'yii\gii\Module',
+                'allowedIPs' => [getenv('GII_ALLOWED_IP','127.0.0.1')],
+            ],
+        ],
+    ];
+}
 return $config;

+ 5 - 1
common/config/main.php

@@ -19,13 +19,17 @@ return [
 			'username' => getenv('DB_USERNAME'),
 			'password' => getenv('DB_PASSWORD'),
 			'charset' => 'utf8mb4',
+			'enableLogging' => false, // 关闭 SQL 日志
+        	'enableProfiling' => false, // 关闭 SQL 性能分析
 		],
 		'db2' => [
 			'class' => 'yii\db\Connection',
 			'dsn' => getenv('DB_DSN_BAK'),
 			'username' => getenv('DB_USERNAME'),
 			'password' => getenv('DB_PASSWORD'),
-			'charset' => 'utf8',
+			'charset' => 'utf8mb4',
+			'enableLogging' => false, // 关闭 SQL 日志
+        	'enableProfiling' => false, // 关闭 SQL 性能分析
 		],
 		'redis' => [
 			'class' => 'yii\redis\Connection',

+ 1 - 1
env.php

@@ -7,4 +7,4 @@ $dotenv = \Dotenv\Dotenv::create(__DIR__);
 $dotenv->load();
 
 defined('YII_DEBUG') or define('YII_DEBUG', getenv('YII_DEBUG') === 'true');
-defined('YII_ENV') or define('YII_ENV', getenv('YII_ENV') ?: 'prod');
+defined('YII_ENV') or define('YII_ENV', getenv('YII_ENV') ?: 'production');