/** * @param array $record * @return array */ public function __invoke(array $record) { // return if the level is not high enough if ($record['level'] < $this->level) { return $record; } $trace = debug_backtrace(); // skip first since it's always the current method array_shift($trace); // the call_user_func call is also skipped array_shift($trace); $i = 0; //dd($trace); while (isset($trace[$i]['class'])) { foreach ($this->skipClassesPartials as $part) { if (strpos($trace[$i]['class'], $part) !== false) { // This is the reason to the existance of this class // I know, it sucks. $i += 3; // Back to normal continue 2; } } break; } // we should have the call source now $record['extra'] = array_merge($record['extra'], array('file' => isset($trace[$i - 1]['file']) ? $trace[$i - 1]['file'] : null, 'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null, 'class' => isset($trace[$i]['class']) ? $trace[$i]['class'] : null, 'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : null, 'environment' => Kernel::env())); return $record; }
/** * Adds a log record at an arbitrary level. * * This method allows for compatibility with common interfaces. * * @param mixed $level The log level * @param string $message The log message * @param array $context The log context * @return bool */ public function log($level = Logger::DEBUG, $message, array $context = []) { $level = static::nameToLevel($level); if (Config::get('kernel.environment.' . Kernel::env() . '.logging') == false) { // Logging is disabled for this environment return false; } return $this->getLogger()->addRecord($level, $message, $context); }
/** * Handles the available handlers and pushes them to the Monolog\Logger instance * * @return void */ protected function pushHandlers() { foreach (Config::get('kernel.logs.handlers') as $handler => $options) { switch ($handler) { case 'RotatingFileHandler': if (!$options['enabled']) { continue; } $level = static::nameToLevel($options['level']); $chmod = 0 . $options['chmod']; /* $class = 'Monolog\\Formatter\\' . $options['formatter']; $formatter = new $class(); */ // Is this handler enabled for this environment? if (array_exists(array_flip($options['environments']), Kernel::env())) { $rotateHandler = new RotatingFileHandler(path('logs') . $options['filename'] . '.log', $options['max'], $level, $chmod); $rotateHandler->setFilenameFormat('{filename}-{date}', $options['date_format']); $this->getLogger()->pushHandler($rotateHandler); } break; case 'BrowserConsoleHandler': if (!$options['enabled']) { continue; } // Is this handler enabled for this environment? if (array_exists(array_flip($options['environments']), Kernel::env())) { $this->getLogger()->pushHandler(new BrowserConsoleHandler()); } break; } } }