writers[spl_object_hash($writer)] = $writer; } /** * @param LogFilter $filter */ public function addFilter(LogFilter $filter) { $this->filters[spl_object_hash($filter)] = $filter; } /** * @return LogWriter[] */ public function getWriters() { return array_values($this->writers); } /** * @return LogFilter[] */ public function getFilters() { return array_values($this->filters); } /** * @param LogWriter $writer */ public function removeWriter(LogWriter $writer) { unset($this->filters[spl_object_hash($writer)]); } /** * @param LogFilter $filter */ public function removeFilter(LogFilter $filter) { unset($this->filters[spl_object_hash($filter)]); } /** * @deprecated Please use LogLevel::mapNameToNumeric() */ public static function mapLogLevel($name) { return LogLevel::mapNameToNumeric($name); } public function emergency($message, array $context = []) { $this->log(__FUNCTION__, $message, $context); } public function alert($message, array $context = []) { $this->log(__FUNCTION__, $message, $context); } public function critical($message, array $context = []) { $this->log(__FUNCTION__, $message, $context); } public function error($message, array $context = []) { $this->log(__FUNCTION__, $message, $context); } public function warning($message, array $context = []) { $this->log(__FUNCTION__, $message, $context); } public function notice($message, array $context = []) { $this->log(__FUNCTION__, $message, $context); } public function info($message, array $context = []) { $this->log(__FUNCTION__, $message, $context); } public function debug($message, array $context = []) { $this->log(__FUNCTION__, $message, $context); } public function wants($level, $message, array $context = []) { foreach ($this->filters as $filter) { if (! $filter->wants($level, $message, $context)) { return false; } } return true; } public function log($level, $message, array $context = []) { if (! $this->wants($level, $message, $context)) { return; } foreach ($this->writers as $writer) { if ($writer instanceof LogWriterWithContext) { $writer->write($level, $message, $context); } else { $writer->write($level, $this->formatMessage( $message, $context )); } } } protected function formatMessage($message, $context = []) { if (empty($context)) { return $message; } else { return \sprintf($message, $context); } } }