public function testOutputWasSet() { $this->config->setOutputHandlers([new FakeOutput()]); $this->assertEquals(1, count($this->config->getOutputHandlers())); $this->config->setOutputHandlers([new FakeOutput(), new UDPOutput('test')]); $this->assertEquals(2, count($this->config->getOutputHandlers())); $this->config->setOutputHandlers([new FakeOutput(), new UDPOutput('test'), new TCPOutput('test')]); $this->assertEquals(3, count($this->config->getOutputHandlers())); }
/** * Send the log data to registered outputs * * @param $logLevel * @param $message * @param array $context * @throws \InvalidArgumentException * @return bool */ protected function output($logLevel, $message, array $context = []) { if ($logLevel < $this->config->getLogLevel()) { return false; } $this->logData = ['app_id' => $this->config->getAppId(), 'channel' => $this->config->getChannel(), 'environment' => $this->config->getEnvironment(), 'message' => (string) $message, 'context' => empty($context) ? null : json_encode($context), 'log_level' => $logLevel, 'log_level_name' => $this->getLogLevelName($logLevel), 'extras' => $this->config->getExtraValues(), 'trace' => $this->backtrace->info(), 'created_at' => $this->config->getDateTimeFormatted()]; foreach ($this->config->getOutputHandlers() as $v) { $v->send(json_encode($this->logData)); } return true; }