/** * Override main() to handle action * Starts a Queuesadilla worker * * @return void */ public function main() { $logger = Log::engine($this->getLoggerName('stdout')); $engine = $this->getEngine($logger); $worker = $this->getWorker($engine, $logger); $worker->work(); }
/** * Get the summary data. * * @return string */ public function summary() { $logger = Log::engine('debug_kit_log_panel'); if (!$logger) { return 0; } return $logger->count(); }
/** * Override main() to handle action * Starts a Queuesadilla worker * * @return void */ public function main() { $engine = $this->params['engine']; $worker = $this->params['worker']; $EngineClass = "josegonzalez\\Queuesadilla\\Engine\\" . $engine . 'Engine'; $WorkerClass = "josegonzalez\\Queuesadilla\\Worker\\" . $worker . "Worker"; $config = $this->getEngineConfig(); $loggerName = $this->getLoggerName(); $logger = Log::engine($loggerName); $engine = new $EngineClass($logger, $config); $worker = new $WorkerClass($engine, $logger); $worker->work(); }
/** * Create the queue engine instance. * * Part of the template method for Cake\Core\ObjectRegistry::load() * * @param string|\josegonzalez\Queuesadilla\Engine\EngineInterface $class The classname or object to make. * @param string $alias The alias of the object. * @param array $settings An array of settings to use for the queue engine. * @return \josegonzalez\Queuesadilla\Engine\EngineInterface The constructed queue engine class. * @throws \RuntimeException when an object doesn't implement the correct interface. */ protected function _create($class, $alias, $settings) { if (is_callable($class)) { $class = $class($alias); } if (is_object($class)) { $instance = $class; } if (!isset($instance)) { $key = PHP_SAPI === 'cli' ? 'stdout' : 'default'; $logger = Hash::get($settings, 'logger', $key); if (!$logger instanceof LoggerInterface) { $logger = Log::engine($logger); } $instance = new $class($logger, $settings); } if ($instance instanceof EngineInterface) { return $instance; } throw new RuntimeException('Queue Engines must implement josegonzalez\\Queuesadilla\\Engine\\EngineInterface.'); }
/** * Tests using a callable for creating a Log engine * * @return void */ public function testCreateLoggerWithCallable() { $instance = new FileLog(); Log::config('default', function () use($instance) { return $instance; }); $this->assertSame($instance, Log::engine('default')); }
/** * Tests that setLoggers works properly with verbose * * @return void */ public function testSetLoggersVerbose() { Log::drop('stdout'); Log::drop('stderr'); $this->io->setLoggers(ConsoleIo::VERBOSE); $this->assertNotEmpty(Log::engine('stderr')); $engine = Log::engine('stdout'); $this->assertEquals(['notice', 'info', 'debug'], $engine->config('levels')); }
/** * Tests that the logged query object is passed to the built-in logger using * the correct scope * * @return void */ public function testLogFunction() { $logger = new QueryLogger(); $query = new LoggedQuery(); $query->query = 'SELECT a FROM b where a = ? AND b = ? AND c = ?'; $query->params = ['string', '3', null]; $engine = $this->getMock('\\Cake\\Log\\Engine\\BaseLog', ['log'], ['scopes' => ['queriesLog']]); Log::engine('queryLoggerTest', $engine); $engine2 = $this->getMock('\\Cake\\Log\\Engine\\BaseLog', ['log'], ['scopes' => ['foo']]); Log::engine('queryLoggerTest2', $engine2); $engine2->expects($this->never())->method('log'); $logger->log($query); }
/** * Tests that setLoggers works properly * * @return void */ public function testSetLoggers() { Log::drop('stdout'); Log::drop('stderr'); $this->io->setLoggers(true); $this->assertNotEmpty(Log::engine('stdout')); $this->assertNotEmpty(Log::engine('stderr')); $this->io->setLoggers(false); $this->assertFalse(Log::engine('stdout')); $this->assertFalse(Log::engine('stderr')); }
/** * Log requests to Elastic Search. * * @param Request|array $context The context of the request made. * @return void */ protected function _log($context) { if (!$this->logQueries) { return; } if (!isset($this->_logger)) { $this->_logger = Log::engine('elasticsearch') ?: new ElasticaLog(); } if ($context instanceof Request) { $data = $context->toArray(); } else { $data = ['message' => $context]; } $logData = ['method' => $data['method'], 'path' => $data['path'], 'data' => $data['data']]; $data = json_encode($logData, JSON_PRETTY_PRINT); $loggedQuery = new LoggedQuery(); $loggedQuery->query = $data; if ($this->_logger instanceof \Psr\Log\LoggerInterface) { $this->_logger->log('debug', $loggedQuery); } else { $this->_logger->log($loggedQuery); } }
/** * testPassingScopeToEngine method */ public function testPassingScopeToEngine() { Configure::write('App.namespace', 'TestApp'); Log::reset(); Log::config('scope_test', ['engine' => 'TestApp', 'types' => array('notice', 'info', 'debug'), 'scopes' => array('foo', 'bar')]); $engine = Log::engine('scope_test'); $this->assertNull($engine->passedScope); Log::write('debug', 'test message', 'foo'); $this->assertEquals(['scope' => ['foo']], $engine->passedScope); Log::write('debug', 'test message', ['foo', 'bar']); $this->assertEquals(['scope' => ['foo', 'bar']], $engine->passedScope); $result = Log::write('debug', 'test message'); $this->assertFalse($result); }