Commit 4e363b37 authored by luhongguang's avatar luhongguang

update:composer update

parent 5cd0f2ac
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"require": { "require": {
"php": "7.2.*", "php": "7.2.*",
"ext-json": "*", "ext-json": "*",
"api/php_utils":"1.0.1", "api/php_utils":"1.0.2",
"api/php_services":"1.0.1", "api/php_services":"1.0.1",
"ext-openssl": "*" "ext-openssl": "*"
}, },
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Api\PhpUtils\Log; namespace Api\PhpUtils\Log;
use Api\PhpUtils\Cache\ApcuUtil; use Api\PhpUtils\Cache\ApcuUtil;
use Api\PhpUtils\Log\Tracer;
use Api\PhpUtils\Message\Email; use Api\PhpUtils\Message\Email;
class FileLog class FileLog
...@@ -17,7 +18,8 @@ class FileLog ...@@ -17,7 +18,8 @@ class FileLog
*/ */
public static function info($signature, $detail_info = '', $with_access_log = false) public static function info($signature, $detail_info = '', $with_access_log = false)
{ {
$log = 'PHP User_info: [' . $signature . ']' . ' [detail info:] ' . $detail_info; $traceId = Tracer::getTraceId();
$log = 'PHP User_info: [' . $signature . '] [traceId:'. $traceId .'] [detail info:] ' . $detail_info;
if ($with_access_log) { if ($with_access_log) {
$log .= ' [request info:] ' . self::accessLog(); $log .= ' [request info:] ' . self::accessLog();
} }
...@@ -33,7 +35,8 @@ class FileLog ...@@ -33,7 +35,8 @@ class FileLog
*/ */
public static function waring($signature, $detail_info = '', $exception = null) public static function waring($signature, $detail_info = '', $exception = null)
{ {
$log = 'PHP User_warning: [' . $signature . ']' . ' [detail info:] ' . $detail_info . ' [request info:] ' . self::accessLog(); $traceId = Tracer::getTraceId();
$log = 'PHP User_warning: [' . $signature . '] [traceId:'. $traceId .'] [detail info:] ' . $detail_info . ' [request info:] ' . self::accessLog();
if ($exception != '') { if ($exception != '') {
$exception_info = 'In ' . $exception->getFile() . ' on line ' . $exception->getLine() . ' ' . $exception->getCode() . ': ' . $exception->getMessage(); $exception_info = 'In ' . $exception->getFile() . ' on line ' . $exception->getLine() . ' ' . $exception->getCode() . ': ' . $exception->getMessage();
$log .= ' [exception info: ]' . $exception_info; $log .= ' [exception info: ]' . $exception_info;
...@@ -51,7 +54,8 @@ class FileLog ...@@ -51,7 +54,8 @@ class FileLog
*/ */
public static function error($signature, $detail_info = '', $exception = null, $mail_to = '') public static function error($signature, $detail_info = '', $exception = null, $mail_to = '')
{ {
$log = 'PHP User_error: [' . $signature . ']' . ' [detail info:] ' . $detail_info . ' [request info:] ' . self::accessLog(); $traceId = Tracer::getTraceId();
$log = 'PHP User_error: [' . $signature . '] [traceId:'. $traceId .'] [detail info:] ' . $detail_info . ' [request info:] ' . self::accessLog();
if ($exception != '') { if ($exception != '') {
$exception_info = ' [exception info: ] In ' . $exception->getFile() . ' on line ' . $exception->getLine() . ' ' . $exception->getCode() . ': ' . $exception->getMessage(); $exception_info = ' [exception info: ] In ' . $exception->getFile() . ' on line ' . $exception->getLine() . ' ' . $exception->getCode() . ': ' . $exception->getMessage();
} else { } else {
......
<?php
namespace Api\PhpUtils\Log;
class Tracer {
const DEBUG = 1;
const INFO = 2;
const WARNING = 3;
const ERROR = 4;
protected static $traceId = '';
protected static $spanId = '';
/**
* http 请求日志
*/
public static function request() {
$tag = 'request';
$message = 'request log';
$content = [
'uri'=>'',
'get'=>[],
'post'=>[],
];
//__METHOD__
self::info($message, $content, $tag);
}
/**
* @param $ret
*/
public static function response($ret) {
$tag = 'response';
$message = 'response log';
$content = [
'ret'=>$ret,
'requestId'=>self::getTraceId(),
];
self::info($message, $content, $tag);
}
public static function daemon() {
$tag = 'daemon';
$message = 'daemon log';
$content = [
'pid'=>posix_getpid(),
];
self::info($message, $content, $tag);
}
/**
* @param $message
* @param array $content
* @param string $tag
*/
public static function debug($message, $content = [], $tag = ''){
self::log(self::DEBUG, $message, $content, $tag);
}
public static function info($message, $content = [], $tag = ''){
self::log(self::INFO, $message, $content, $tag);
}
public static function warning($message, $content = [], $tag = '') {
self::log(self::WARNING, $message, $content, $tag);
}
public static function error($message, $content = [], $tag = '') {
self::log(self::ERROR, $message, $content, $tag);
}
public static function log($level, $message, $content, $tag) {
if (!defined('LOG_PATH')) {
define('LOG_PATH', ROOT_PATH.'/logs/');
}
switch ($level) {
case self::DEBUG:
case self::INFO:
case self::WARNING:
case self::ERROR:
$file = LOG_PATH . 'log_' . date('Y-m-d') . '.log';
break;
}
$dateTime = new \DateTime();
$log = [
'timestamp'=>$dateTime->format(\DateTime::RFC3339_EXTENDED),
'traceId'=>self::getTraceId(),
'spanId'=>self::getSpanId(),
'tag'=>$tag,
'content'=>$content,
'message'=>$message
];
//$_SERVER['HTTP_X_FORWARDED_FOR']
$string = json_encode($log, JSON_UNESCAPED_UNICODE) . "\n";
if($fd = @fopen($file, 'a')) {
fputs($fd, $string);
fclose($fd);
}
}
/**
* @return false|mixed|string
* 获取traceId
*/
public static function getTraceId() {
if(empty(self::$traceId)) {
if(!empty($_SERVER['HTTP_X_TRACE_ID'])) {
self::$traceId = $_SERVER['HTTP_X_TRACE_ID'];
} elseif(!empty($_SERVER['HTTP_X_REQUEST_ID'])) {
self::$traceId = $_SERVER['HTTP_X_REQUEST_ID'];
} else {
self::$traceId = self::genUniqId();
}
}
return self::$traceId;
}
/**
* @return false|string
* 获取spanId
*/
public static function getSpanId() {
if(empty(self::$spanId)) {
self::$spanId = self::genUniqId();
}
return self::$spanId;
}
/**
* @return false|string
* @throws \Exception
* 获取随机串用于记录traceId
*/
public static function genUniqId() {
if (function_exists("random_bytes")) {
$bytes = random_bytes(ceil(8));
return substr(bin2hex($bytes), 0, 16);
} elseif (function_exists("openssl_random_pseudo_bytes")) {
$bytes = openssl_random_pseudo_bytes(ceil(8));
return substr(bin2hex($bytes), 0, 16);
} else {
$pre = rand(1, 4095);
return uniqid(sprintf("%03x", $pre));
}
}
}
...@@ -27,12 +27,12 @@ class InstalledVersions ...@@ -27,12 +27,12 @@ class InstalledVersions
private static $installed = array ( private static $installed = array (
'root' => 'root' =>
array ( array (
'pretty_version' => 'dev-develop', 'pretty_version' => 'dev-master',
'version' => 'dev-develop', 'version' => 'dev-master',
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => '878a33618ec71ce36e62220c8e1be7e813733fe3', 'reference' => '5cd0f2ace54fdc6b7e0a0d389e3e8030559220fd',
'name' => 'yidian/yaf_demo', 'name' => 'yidian/yaf_demo',
), ),
'versions' => 'versions' =>
...@@ -48,12 +48,12 @@ private static $installed = array ( ...@@ -48,12 +48,12 @@ private static $installed = array (
), ),
'api/php_utils' => 'api/php_utils' =>
array ( array (
'pretty_version' => 'v1.0.1', 'pretty_version' => 'v1.0.2',
'version' => '1.0.1.0', 'version' => '1.0.2.0',
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => '26abffd9afc5b90b7f42f10cf21813bbc3dd4f2d', 'reference' => '98d1aea6e76f55b2bfdd38c897fc6a8faa2bc722',
), ),
'bacon/bacon-qr-code' => 'bacon/bacon-qr-code' =>
array ( array (
...@@ -327,12 +327,12 @@ private static $installed = array ( ...@@ -327,12 +327,12 @@ private static $installed = array (
), ),
'yidian/yaf_demo' => 'yidian/yaf_demo' =>
array ( array (
'pretty_version' => 'dev-develop', 'pretty_version' => 'dev-master',
'version' => 'dev-develop', 'version' => 'dev-master',
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => '878a33618ec71ce36e62220c8e1be7e813733fe3', 'reference' => '5cd0f2ace54fdc6b7e0a0d389e3e8030559220fd',
), ),
), ),
); );
......
...@@ -66,6 +66,7 @@ return array( ...@@ -66,6 +66,7 @@ return array(
'Api\\PhpUtils\\Lock\\FrequencyLockUtil' => $vendorDir . '/api/php_utils/src/Lock/FrequencyLockUtil.php', 'Api\\PhpUtils\\Lock\\FrequencyLockUtil' => $vendorDir . '/api/php_utils/src/Lock/FrequencyLockUtil.php',
'Api\\PhpUtils\\Log\\DaemonLog' => $vendorDir . '/api/php_utils/src/Log/DaemonLog.php', 'Api\\PhpUtils\\Log\\DaemonLog' => $vendorDir . '/api/php_utils/src/Log/DaemonLog.php',
'Api\\PhpUtils\\Log\\FileLog' => $vendorDir . '/api/php_utils/src/Log/FileLog.php', 'Api\\PhpUtils\\Log\\FileLog' => $vendorDir . '/api/php_utils/src/Log/FileLog.php',
'Api\\PhpUtils\\Log\\Tracer' => $vendorDir . '/api/php_utils/src/Log/Tracer.php',
'Api\\PhpUtils\\Message\\Email' => $vendorDir . '/api/php_utils/src/Message/Email.php', 'Api\\PhpUtils\\Message\\Email' => $vendorDir . '/api/php_utils/src/Message/Email.php',
'Api\\PhpUtils\\Mon\\MonUtil' => $vendorDir . '/api/php_utils/src/Mon/MonUtil.php', 'Api\\PhpUtils\\Mon\\MonUtil' => $vendorDir . '/api/php_utils/src/Mon/MonUtil.php',
'Api\\PhpUtils\\Mon\\TimeCostUtil' => $vendorDir . '/api/php_utils/src/Mon/TimeCostUtil.php', 'Api\\PhpUtils\\Mon\\TimeCostUtil' => $vendorDir . '/api/php_utils/src/Mon/TimeCostUtil.php',
......
...@@ -295,6 +295,7 @@ class ComposerStaticInit5871a7b0b10b793d91ef1c8029b23ea5 ...@@ -295,6 +295,7 @@ class ComposerStaticInit5871a7b0b10b793d91ef1c8029b23ea5
'Api\\PhpUtils\\Lock\\FrequencyLockUtil' => __DIR__ . '/..' . '/api/php_utils/src/Lock/FrequencyLockUtil.php', 'Api\\PhpUtils\\Lock\\FrequencyLockUtil' => __DIR__ . '/..' . '/api/php_utils/src/Lock/FrequencyLockUtil.php',
'Api\\PhpUtils\\Log\\DaemonLog' => __DIR__ . '/..' . '/api/php_utils/src/Log/DaemonLog.php', 'Api\\PhpUtils\\Log\\DaemonLog' => __DIR__ . '/..' . '/api/php_utils/src/Log/DaemonLog.php',
'Api\\PhpUtils\\Log\\FileLog' => __DIR__ . '/..' . '/api/php_utils/src/Log/FileLog.php', 'Api\\PhpUtils\\Log\\FileLog' => __DIR__ . '/..' . '/api/php_utils/src/Log/FileLog.php',
'Api\\PhpUtils\\Log\\Tracer' => __DIR__ . '/..' . '/api/php_utils/src/Log/Tracer.php',
'Api\\PhpUtils\\Message\\Email' => __DIR__ . '/..' . '/api/php_utils/src/Message/Email.php', 'Api\\PhpUtils\\Message\\Email' => __DIR__ . '/..' . '/api/php_utils/src/Message/Email.php',
'Api\\PhpUtils\\Mon\\MonUtil' => __DIR__ . '/..' . '/api/php_utils/src/Mon/MonUtil.php', 'Api\\PhpUtils\\Mon\\MonUtil' => __DIR__ . '/..' . '/api/php_utils/src/Mon/MonUtil.php',
'Api\\PhpUtils\\Mon\\TimeCostUtil' => __DIR__ . '/..' . '/api/php_utils/src/Mon/TimeCostUtil.php', 'Api\\PhpUtils\\Mon\\TimeCostUtil' => __DIR__ . '/..' . '/api/php_utils/src/Mon/TimeCostUtil.php',
......
...@@ -27,12 +27,12 @@ ...@@ -27,12 +27,12 @@
}, },
{ {
"name": "api/php_utils", "name": "api/php_utils",
"version": "v1.0.1", "version": "v1.0.2",
"version_normalized": "1.0.1.0", "version_normalized": "1.0.2.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.yidian-inc.com:8021/bp/php_utils.git", "url": "https://git.yidian-inc.com:8021/bp/php_utils.git",
"reference": "26abffd9afc5b90b7f42f10cf21813bbc3dd4f2d" "reference": "98d1aea6e76f55b2bfdd38c897fc6a8faa2bc722"
}, },
"require": { "require": {
"elasticsearch/elasticsearch": "~7.0", "elasticsearch/elasticsearch": "~7.0",
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
"mongodb/mongodb": "1.4.3", "mongodb/mongodb": "1.4.3",
"php": "7.2.*" "php": "7.2.*"
}, },
"time": "2021-08-02T13:20:23+00:00", "time": "2021-08-03T02:31:09+00:00",
"type": "library", "type": "library",
"installation-source": "source", "installation-source": "source",
"autoload": { "autoload": {
......
<?php return array ( <?php return array (
'root' => 'root' =>
array ( array (
'pretty_version' => 'dev-develop', 'pretty_version' => 'dev-master',
'version' => 'dev-develop', 'version' => 'dev-master',
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => '878a33618ec71ce36e62220c8e1be7e813733fe3', 'reference' => '5cd0f2ace54fdc6b7e0a0d389e3e8030559220fd',
'name' => 'yidian/yaf_demo', 'name' => 'yidian/yaf_demo',
), ),
'versions' => 'versions' =>
...@@ -22,12 +22,12 @@ ...@@ -22,12 +22,12 @@
), ),
'api/php_utils' => 'api/php_utils' =>
array ( array (
'pretty_version' => 'v1.0.1', 'pretty_version' => 'v1.0.2',
'version' => '1.0.1.0', 'version' => '1.0.2.0',
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => '26abffd9afc5b90b7f42f10cf21813bbc3dd4f2d', 'reference' => '98d1aea6e76f55b2bfdd38c897fc6a8faa2bc722',
), ),
'bacon/bacon-qr-code' => 'bacon/bacon-qr-code' =>
array ( array (
...@@ -301,12 +301,12 @@ ...@@ -301,12 +301,12 @@
), ),
'yidian/yaf_demo' => 'yidian/yaf_demo' =>
array ( array (
'pretty_version' => 'dev-develop', 'pretty_version' => 'dev-master',
'version' => 'dev-develop', 'version' => 'dev-master',
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => '878a33618ec71ce36e62220c8e1be7e813733fe3', 'reference' => '5cd0f2ace54fdc6b7e0a0d389e3e8030559220fd',
), ),
), ),
); );
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