企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ <?php /** * Created by PhpStorm. * User: baidu * Date: 17/8/6 * Time: 上午2:45 */ namespace app\index\common; use think\Log; class Logs { //sentry日志收集器 static public function sentryLogs($e,$line,array $data = []) { Log::init([ 'type' => 'File', 'path' => LOG_PATH, ]); $sentryClient = new \Raven_Client( 'https://c5485e6c233347ca8a7990a2bf77514a:9a69f3eb68c446f8ae3247eb368c1ff6@sentry.io/1193480', [ 'name' => \Raven_Compat::gethostname(),//服务器主机名 'environment' => 'production', 'level' => 'error', //附加数据 'extra' => $data, 'app_path' => ROOT_PATH, 'sample_rate' => 1,//值0.00将拒绝发送任何事件,值1.00将发送100%的事件。 'curl_method' => 'async',//curl异步发送,比同步体验好很多 //回掉方法,在发送数据之前操作 'send_callback' => function ($data) { }, ]); //单独设置用户信息 $sentryClient->user_context([ 'id' => 2966, 'username' => 'chenjing', 'email' => '465497241@qq.com', 'mobile' => '153****874', 'ip_address' => $_SERVER['REMOTE_ADDR'] ]); if ( $e && is_object($e) ) { $sentryClient->captureException($e); $errorMsg = "\n文件:".$e->getFile()."\n行数:".$e->getLine()."\n错误代码:".$e->getCode()."\n错误信息:".$e->getMessage()."\n"; }else{ //当没有异常只想记录信息的时候可以使用这个 $sentryClient->captureMessage($e); $errorMsg = $e."\n行数:".$line; } Log::record($errorMsg); } } ~~~