/** * 例外をレポート、もしくはログ * * ここはSentryやBugsnagなどに例外を送るために良い場所 * * @param \Exception $e * @return void */ public function report(Exception $e) { if (!$e instanceof NotFoundHttpException) { $slack = new SlackBot(); $slack->post($e->getMessage() . PHP_EOL . print_r($e->getTrace()[0], true)); } return parent::report($e); }
/** * Execute the console command. * * @return mixed */ public function handle() { $text = 'report date: '; $analysis = $this->analysis->where('date', date('Ymd', strtotime('-1 day')))->first(); if ($analysis) { $text .= date('Y/m/d', strtotime($analysis->created_at)); $text .= PHP_EOL; $text .= "page_view: {$analysis->page_view}"; $text .= PHP_EOL; $text .= "new_post: {$analysis->new_post}"; } else { $text .= $text = date('Y/m/d', strtotime('-1 day')); $text .= PHP_EOL; $text .= "page_view: 0"; $text .= PHP_EOL; $text .= "new_post: 0"; } $this->slackBot->post($text); }
/** * エラーをSlackへ送信する * @Post("/error", as="error.postError") * @param ErrorPostRequest $request * @return \Illuminate\Http\Response */ public function postError(ErrorPostRequest $request) { $text = sprintf('msg: %s, url: %s, col: %s', $request->msg, $request->url, $request->col); $this->slackBot->post($text); return response(''); }