Commit ce587b0c authored by Euan游根明's avatar Euan游根明

perf: 写入日志

parent 59a94a9c
...@@ -210,7 +210,7 @@ class Nacos ...@@ -210,7 +210,7 @@ class Nacos
* @return mixed|string * @return mixed|string
*/ */
public static function NacosGet($key){ public static function NacosGet($key){
$path =self::getPath(sys_get_temp_dir(), '/nacos.cache-'.md5(self::$configs['GROUP'])).self::$configs['APP_ENV']; $path =self::getPath(sys_get_temp_dir(), '/nacos.cache-'.md5(self::$configs['GROUP'])).'-'.self::$configs['APP_ENV'];
if (!file_exists($path)) { if (!file_exists($path)) {
return ''; return '';
} }
...@@ -231,7 +231,7 @@ class Nacos ...@@ -231,7 +231,7 @@ class Nacos
* @return false|int * @return false|int
*/ */
public static function NacosPut($key,$value){ public static function NacosPut($key,$value){
$path = self::getPath(sys_get_temp_dir(), '/nacos.cache-'.md5(self::$configs['GROUP'])).self::$configs['APP_ENV']; $path = self::getPath(sys_get_temp_dir(), '/nacos.cache-'.md5(self::$configs['GROUP'])).'-'.self::$configs['APP_ENV'];
if (!file_exists($path)) { if (!file_exists($path)) {
$data[$key] = $value; $data[$key] = $value;
return file_put_contents($path, json_encode($data)); return file_put_contents($path, json_encode($data));
...@@ -300,20 +300,25 @@ class Nacos ...@@ -300,20 +300,25 @@ class Nacos
/** /**
* 写入日志 * 写入日志
* @return void * @param $logData
* @return false|int
*/ */
public static function writeLog($logData){ public static function writeLog($logData){
$logFile = '/nacos-'.self::$configs['GROUP'].'-'.date('Y-m-d').'.log'; $logFile = '/nacos-'.self::$configs['GROUP'].'-'.date('Y-m-d').'.log';
$path = self::getPath(sys_get_temp_dir(),$logFile); $path = self::getPath(sys_get_temp_dir(),$logFile);
if (!is_string($logData)){
$logData = json_encode($logData);
}
if (!file_exists($path)) {
$data[] = $logData;
return file_put_contents($path, json_encode($data));
}
$data = json_decode( $data = json_decode(
file_get_contents($path), file_get_contents($path),
true, true,
); );
if (!is_string($logData)){
$logData = json_encode($logData,);
}
$data[] = $logData; $data[] = $logData;
file_put_contents( return file_put_contents(
$path, $path,
json_encode($data), json_encode($data),
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment