Ejemplo n.º 1
0
 public function index(Request $request)
 {
     $start_date = $request->get('start_date', null);
     $end_date = $request->get('end_date', null);
     $level = $request->get('level', null);
     $message = $request->get('message', null);
     if (config('glog.db_connection') == 'mongodb') {
         $logger = new MongoDbLogger();
     } else {
         $logger = new MySqlLogger();
     }
     $logs = $logger->where(function ($query) use($start_date) {
         if ($start_date != null) {
             $query->whereRaw("DATE(created_at) >= DATE('{$start_date}')");
         }
     })->where(function ($query) use($end_date) {
         if ($end_date != null) {
             $query->whereRaw("DATE(created_at) <= DATE('{$end_date}')");
         }
     })->where(function ($query) use($level) {
         if ($level != null) {
             $query->where("level_name", $level);
         }
     })->where(function ($query) use($message) {
         if ($message != null) {
             $query->where("message", $message);
         }
     })->orderBy('created_at', 'desc')->paginate(100);
     $translations = config('glog.translations');
     $levels = config('glog.levels');
     $channels = config('glog.channels');
     $labels = ['EMERGENCY' => 'danger', 'ALERT' => 'danger', 'CRITICAL' => 'yellow', 'ERROR' => 'danger', 'WARNING' => 'warning', 'NOTICE' => 'default', 'INFO' => 'info', 'DEBUG' => 'success'];
     return view('glog::index', compact('logs', 'translations', 'levels', 'level', 'message', 'start_date', 'end_date', 'channels', 'labels'));
 }
Ejemplo n.º 2
0
 protected function write(array $record)
 {
     $hasLevel = in_array($record['level_name'], config('glog.levels'));
     $hasChannel = in_array($record['message'], config('glog.channels'));
     $notifications = config('glog.notification');
     $send_notification = 0;
     foreach ($notifications as $key => $value) {
         if ($key === $record['message']) {
             $send_notification = in_array($record['level_name'], $value);
         }
     }
     if ($send_notification) {
         $messages = config('glog.messages');
         $data = ['record' => $record, 'action' => isset($messages[$record['message']]) ? $messages[$record['message']] : $record['message']];
         Mail::send("glog::email.notification", $data, function ($message) {
             $message->to(config('glog.mail_to'))->subject(config('glog.mail_subject'));
         });
     }
     if ($hasLevel && $hasChannel) {
         if (config('glog.service', 'local') === 'remote') {
             $this->post_remote($record);
         } else {
             if (config('glog.db_connection') == 'mongodb') {
                 MongoDbLogger::create(['channel' => $record['message'], 'context' => json_encode($record['context']), 'level' => $record['level'], 'level_name' => $record['level_name']]);
             } else {
                 MySqlLogger::create(['channel' => $record['message'], 'context' => json_encode($record['context']), 'level' => $record['level'], 'level_name' => $record['level_name']]);
             }
         }
     }
 }