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
@ -7,63 +7,87 @@
|
||||
namespace Home\ORG;
|
||||
|
||||
|
||||
class ApiLog {
|
||||
class ApiLog{
|
||||
|
||||
private static $appInfo = 'null';
|
||||
private static $apiInfo = 'null';
|
||||
private static $request = 'null';
|
||||
private static $requestAfterFilter = 'null';
|
||||
private static $response = 'null';
|
||||
private static $header = 'null';
|
||||
private static $userInfo = 'null';
|
||||
private static $appInfo = 'null';
|
||||
private static $apiInfo = 'null';
|
||||
private static $request = 'null';
|
||||
private static $requestAfterFilter = 'null';
|
||||
private static $response = 'null';
|
||||
private static $header = 'null';
|
||||
private static $userInfo = 'null';
|
||||
private static $separator = '###';
|
||||
|
||||
public static function setAppInfo($data) {
|
||||
self::$appInfo = $data['app_id'] . "({$data['app_name']}) {$data['device_id']}";
|
||||
}
|
||||
public static function setAppInfo($data){
|
||||
self::$appInfo = $data['app_id'] . "({$data['app_name']}) {$data['device_id']}";
|
||||
}
|
||||
|
||||
public static function setHeader($data) {
|
||||
$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';
|
||||
self::$header = $accessToken.' '.$userToken.' '.$data['VERSION'];
|
||||
}
|
||||
public static function setHeader($data){
|
||||
$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';
|
||||
self::$header = $accessToken . self::$separator . $userToken . self::$separator . $data['VERSION'] . self::$separator . $cas;
|
||||
}
|
||||
|
||||
public static function setApiInfo($data) {
|
||||
self::$apiInfo = $data['apiName'] . ' ' . $data['hash'];
|
||||
}
|
||||
public static function setApiInfo($data){
|
||||
self::$apiInfo = $data['apiName'] . self::$separator . $data['hash'];
|
||||
}
|
||||
|
||||
public static function setUserInfo($data) {
|
||||
if (is_array($data)) {
|
||||
$data = json_encode($data);
|
||||
}
|
||||
self::$userInfo = $data;
|
||||
}
|
||||
public static function setUserInfo($data){
|
||||
if (is_array($data)) {
|
||||
$data = json_encode($data);
|
||||
}
|
||||
self::$userInfo = $data;
|
||||
}
|
||||
|
||||
public static function setRequest($data) {
|
||||
if (is_array($data)) {
|
||||
$data = json_encode($data);
|
||||
}
|
||||
self::$request = $data;
|
||||
}
|
||||
public static function setRequest($data){
|
||||
if (is_array($data)) {
|
||||
$data = json_encode($data);
|
||||
}
|
||||
self::$request = $data;
|
||||
}
|
||||
|
||||
public static function setRequestAfterFilter($data) {
|
||||
if (is_array($data)) {
|
||||
$data = json_encode($data);
|
||||
}
|
||||
self::$requestAfterFilter = $data;
|
||||
}
|
||||
public static function setRequestAfterFilter($data){
|
||||
if (is_array($data)) {
|
||||
$data = json_encode($data);
|
||||
}
|
||||
self::$requestAfterFilter = $data;
|
||||
}
|
||||
|
||||
public static function setResponse($data) {
|
||||
if (is_array($data)) {
|
||||
$data = json_encode($data);
|
||||
}
|
||||
self::$response = $data;
|
||||
}
|
||||
public static function setResponse($data){
|
||||
if (is_array($data)) {
|
||||
$data = json_encode($data);
|
||||
}
|
||||
self::$response = $data;
|
||||
}
|
||||
|
||||
public static function save(){
|
||||
$logPath = APP_PATH . '/ApiLog/' . date('YmdH') . '.log';
|
||||
$logStr = implode(self::$separator, array(
|
||||
self::$apiInfo,
|
||||
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);
|
||||
}
|
||||
|
||||
public static function save() {
|
||||
$logPath = APP_PATH . '/ApiLog/' . date('YmdH') . '.log';
|
||||
$logStr = self::$apiInfo . ' ' . date('H:i:s') . ' ' . self::$request . ' ' . self::$header . ' '
|
||||
. self::$response . ' ' . self::$requestAfterFilter . ' ' . self::$appInfo.' '.self::$userInfo."\n";
|
||||
@file_put_contents($logPath, $logStr, FILE_APPEND);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user