mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified ApiLog分隔符优化 添加writeLog方法
modified: Application/Home/ORG/ApiLog.class.php
This commit is contained in:
parent
da7e7bfcb9
commit
22f3bba4aa
@ -16,6 +16,7 @@ class ApiLog {
|
|||||||
private static $response = 'null';
|
private static $response = 'null';
|
||||||
private static $header = 'null';
|
private static $header = 'null';
|
||||||
private static $userInfo = 'null';
|
private static $userInfo = 'null';
|
||||||
|
private static $separator = '###';
|
||||||
|
|
||||||
public static function setAppInfo($data){
|
public static function setAppInfo($data){
|
||||||
self::$appInfo = $data['app_id'] . "({$data['app_name']}) {$data['device_id']}";
|
self::$appInfo = $data['app_id'] . "({$data['app_name']}) {$data['device_id']}";
|
||||||
@ -24,11 +25,11 @@ class ApiLog {
|
|||||||
public static function setHeader($data){
|
public static function setHeader($data){
|
||||||
$userToken = (isset($data['USER-TOKEN']) && !empty($data['USER-TOKEN'])) ? $data['USER-TOKEN'] : 'null';
|
$userToken = (isset($data['USER-TOKEN']) && !empty($data['USER-TOKEN'])) ? $data['USER-TOKEN'] : 'null';
|
||||||
$accessToken = (isset($data['ACCESS-TOKEN']) && !empty($data['ACCESS-TOKEN'])) ? $data['ACCESS-TOKEN'] : 'null';
|
$accessToken = (isset($data['ACCESS-TOKEN']) && !empty($data['ACCESS-TOKEN'])) ? $data['ACCESS-TOKEN'] : 'null';
|
||||||
self::$header = $accessToken.' '.$userToken.' '.$data['VERSION'];
|
self::$header = $accessToken . self::$separator . $userToken . self::$separator . $data['VERSION'] . self::$separator . $cas;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setApiInfo($data){
|
public static function setApiInfo($data){
|
||||||
self::$apiInfo = $data['apiName'] . ' ' . $data['hash'];
|
self::$apiInfo = $data['apiName'] . self::$separator . $data['hash'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function setUserInfo($data){
|
public static function setUserInfo($data){
|
||||||
@ -61,9 +62,32 @@ class ApiLog {
|
|||||||
|
|
||||||
public static function save(){
|
public static function save(){
|
||||||
$logPath = APP_PATH . '/ApiLog/' . date('YmdH') . '.log';
|
$logPath = APP_PATH . '/ApiLog/' . date('YmdH') . '.log';
|
||||||
$logStr = self::$apiInfo . ' ' . date('H:i:s') . ' ' . self::$request . ' ' . self::$header . ' '
|
$logStr = implode(self::$separator, array(
|
||||||
. self::$response . ' ' . self::$requestAfterFilter . ' ' . self::$appInfo.' '.self::$userInfo."\n";
|
self::$apiInfo,
|
||||||
@file_put_contents($logPath, $logStr, FILE_APPEND);
|
date('H:i:s'),
|
||||||
|
self::$request,
|
||||||
|
self::$header,
|
||||||
|
self::$response,
|
||||||
|
self::$requestAfterFilter,
|
||||||
|
self::$appInfo,
|
||||||
|
self::$userInfo
|
||||||
|
));
|
||||||
|
|
||||||
|
@file_put_contents($logPath, $logStr . "\n", FILE_APPEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $log 被记录的内容
|
||||||
|
* @param string $type 日志文件名称
|
||||||
|
* @param string $filePath
|
||||||
|
*/
|
||||||
|
public static function writeLog($log, $type = 'sql', $filePath = './Application/Runtime/'){
|
||||||
|
$filename = $filePath . date("Ymd") . '_' . $type . ".log";
|
||||||
|
@$handle = fopen($filename, "a+");
|
||||||
|
@fwrite($handle, date('Y-m-d H:i:s') . "\t" . $log . "\r\n");
|
||||||
|
@fclose($handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user