/** * Check if this handler can handle the given Record * * @param Record $record * * @return bool Boolean telling whether this handler can handle the given Record */ public function canHandle(Record $record) { if ($this->levels->count() < 1) { return true; } return $this->levels->inArray($record->getLevel()); }
public function formatRecords(array $records, Record $record) { $message = ''; foreach ($records as $r) { $message .= $this->formatRecord($r); } $record->setFormattedRecord($message); }
/** * Processes a log record. * * @param Record $record A record to process * */ public function processRecord(Record $record) { $backtrace = debug_backtrace(); $backtrace = $backtrace[5]; $extraData = $record->getExtra(); $extraData['file'] = $backtrace['file']; $extraData['line'] = $backtrace['line']; $record->setExtra($extraData); }
/** * Adds a log record. * * @param integer $level The logging level * @param string $message The log message * @param array $context The log context * * @throws LoggerException * @return Boolean Whether the record has been processed */ protected function addRecord($level, $message, array $context = array()) { if ($this->handlers->count() < 1) { throw new LoggerException('To log a record you must add at least one HandlerAbstract object to handle the messages.'); } $record = new Record(); $record->setLoggerName($this->name); $record->setMessage((string) $message); $record->setContext($context); $record->setLevel($level); $record->setDatetime($this->datetime("now")); // check if any handler will handle this message $canHandle = false; foreach ($this->handlers as $handler) { if ($handler->canHandle($record)) { $canHandle = true; break; } } if (!$canHandle) { return false; } /* @var $handler Webiny\HandlerAbstract */ foreach ($this->handlers as $handler) { if ($handler->canHandle($record)) { $bubble = $handler->process(clone $record); if (!$bubble) { break; } } } return true; }
/** * Processes a log record. * * @param Record $record Log record to process */ public function processRecord(Record $record) { $extraData = $record->getExtra(); $extraData['memoryUsage'] = memory_get_usage(true); $record->setExtra($extraData); }
/** * Writes the record down to the log of the implementing handler * * @param Record $record * * @return void */ protected function write(Record $record) { $this->file->setContents($record->getFormattedRecord(), true); }