protected function log($log) { if (is_array($log)) { $log = print_r($log, true); } $this->logger->info($log); }
/** * Init profiler */ public function initProfiler(MvcEvent $e) { try { $writer = new FirePhp(); $logger = new Logger(); $logger->addWriter($writer); $logger->info('memory usage: ' . memory_get_usage(true) / 1024 / 1024 . 'Mb'); $logger->info('page execution time: ' . (microtime(true) - APPLICATION_START)); // get sql profiler if (null !== ($sqlProfiler = $this->serviceLocator->get('Zend\\Db\\Adapter\\Adapter')->getProfiler())) { $queriesTotalTime = 0; foreach ($sqlProfiler->getProfiles() as $query) { $base = ['time' => $query['elapse'], 'query' => $query['sql']]; $queriesTotalTime += $query['elapse']; if (!empty($query['parameters'])) { $params = []; foreach ($query['parameters'] as $key => $value) { $params[$key] = $value; } $base['params'] = $params; } $logger->info('', $base); } $logger->info('sql queries total execution time: ' . $queriesTotalTime); } } catch (Exception $e) { ApplicationErrorLogger::log($e); } }
/** * Log de info * @param string $pathLog caminho do erro * @param string $message mensagem de erro * @return boolean */ public static function info($pathLog, $message) { self::createLogger(); self::$logger->addWriter(new \Zend\Log\Writer\Stream($pathLog . DIRECTORY_SEPARATOR . "info.log")); self::$logger->info($message); self::destroyLogger(); return TRUE; }
public function stopQuery() { if ($this->enabled) { parent::stopQuery(); $q = $this->queries[$this->currentQuery]; $message = "Executed Query: " . print_r($q, true); $this->logger->info($message); } }
public function testSetSubjectPrependText() { $this->writer->setSubjectPrependText('test'); $this->log->info('an info message'); $this->log->info('a second info message'); unset($this->log); $contents = file_get_contents(__DIR__ . '/' . self::FILENAME); $this->assertContains('an info message', $contents); $this->assertContains('Subject: test', $contents); }
/** * Log a message * * @param string $message Message to be logged */ public function logMessage($message) { $this->logger->info(strip_tags($message)); if ($this->sendToBrowser) { $this->sendMessageToBrowser($message); } if ($this->sendToCli) { $this->sendMessageToCli($message); } }
/** * @return bool */ private function logIssues() { if (!$this->isVerbose()) { return false; } $form = $this->userService->getRegisterForm(); foreach ($form->getMessages() as $key => $messages) { foreach ($messages as $issueKey => $issueMessage) { $this->logger->info($key . '/' . $issueKey . ': ' . $issueMessage); } } return true; }
public function run(Command $cmd) { $command = $this->bin . ' ' . (string) $cmd; $this->logger->debug('Command : `' . $command . '``'); $proc = popen((string) $command, 'r'); while (($line = fgets($proc)) !== false) { foreach ($this->handler as $handler) { $handler->handle($line, $this, $cmd); } } $this->logger->info('Done.'); /** @var HandlerInterface[] $handlers */ return array_merge($this->handler, $this->ignoredHandler); }
public function showAction() { $url = $this->getEvent()->getRouteMatch()->getParam('url'); $this->logger->info('Preparing scan for `' . $url . '`'); $client = $this->client; $client->addHandler(new UrlHandler()); $client->addHandler(new PluginHandler()); $client->addHandler(new TemplateHandler()); $command = new Command(); $command->addArgs(new Url($url)); $command->addArgs(new FakeUserAgent()); $result = $client->run($command); foreach ($result as $handler) { $this->console->writeLine($handler->__toString()); } }
/** * Callback function invoking on successful mail sent * * @param Event $e */ public function onMailSent(Event $e) { /* @var Message */ $message = $e->getTarget(); $addressList = $this->prepareAddressList($message); $this->logger->info(sprintf("E-mail '%s' has been sent to following recipients: %s", $message->getSubject(), implode(', ', $addressList))); }
/** * console($text, $exception = false, $exit = false) Output console message * @param string $data stdout data * @param boolean $exception throwed Eception * @param boolean $exit die console out * @acceess public */ public function console($data, $exception = false, $exit = false) { // check if console is usable if (true === $this->config['debug']) { if (is_array($data) || is_object($data)) { Debug::dump($data . '', date('[Y-m-d H:i:s]') . ' [DEBUG]'); if (isset($this->__log)) { $this->_logger->info($data); } } else { if (!is_resource($data)) { $data = mb_convert_encoding($data, $this->config['encoding']); } $text = date('[Y-m-d H:i:s]') . '[DEBUG] ' . $data . "\r\n"; if ($exception) { if ($this->__log) { $this->_logger->crit($text); } throw new Exception\ExceptionStrategy($text); } else { if ($this->__log) { $this->_logger->info($text); } echo $text; } } if ($exit) { $this->shutdown(); } } }
/** * @param Message $message * * @return bool */ private function closeSentMessage(Message $message) { $queue = $message->getQueue(); if (empty($queue)) { return false; } $allSent = true; foreach ($queue as $queueItem) { if (null === $queueItem->getSentAt()) { $allSent = false; break; } } if ($this->isVerbose()) { $messageAsString = $this->messageToString($message, count($queue)); if ($allSent) { $this->logger->info('Message to be closed: ' . $messageAsString); } else { $this->logger->info('Message is still being sent: ' . $messageAsString); } } if ($allSent) { $this->messageRepository->closeMessage($message); return true; } return false; }
public function transactionReceived(string $address, float $amount) { $this->logger->notice("Received transaction to address {$address}"); $stmt = $this->connection->prepare('UPDATE addresses SET last_used = NULL WHERE address = :address'); $stmt->execute([':address' => $address]); $addressMaxAge = new \DateTime($this->addressLockTime); $stmt = $this->connection->prepare('SELECT id, ordered_genre_id, price FROM orders WHERE address = :address AND ordered > :maxAge AND paid = FALSE'); $stmt->execute([':address' => $address, ':maxAge' => $addressMaxAge->format("Y-m-d H:i:s")]); $result = $stmt->fetch(PDO::FETCH_ASSOC); $orderId = $result['id']; $orderedGenreId = $result['ordered_genre_id']; $price = $result['price']; if ($price > $amount) { //if paid amount is smaller than ordered price return; } $stmt = $this->connection->prepare('UPDATE orders SET paid = TRUE WHERE address = :address AND ordered > :maxAge AND paid = FALSE'); $stmt->execute([':address' => $address, ':maxAge' => $addressMaxAge->format("Y-m-d H:i:s")]); if ($orderedGenreId != null) { file_put_contents($this->currentGenreFile, $orderedGenreId); } $this->logger->info("{$orderId} has been paid"); $stmt = $this->connection->prepare('UPDATE queue SET paid = TRUE WHERE order_id = :id'); $stmt->execute([':id' => $orderId]); }
/** * * @param string $message * @param array $extra */ public static function logInfo($message, array $extra = array()) { if (is_null(self::$logger)) { throw new ProcessException("Impossible de loguer le message d'information : " . $message); } else { self::$logger->info($message, $extra); } }
public function perform() { $queueName = isset($this->args['name']) ? $this->args['name'] : 'error'; $writer = new Log\Writer\Stream(EVA_PUBLIC_PATH . '/logs/' . $queueName . '.log'); $logger = new Log\Logger(); $logger->addWriter($writer); $logger->info("Worker {$queueName} is working"); }
private static function errorWriter($message) { // log the message to the error file $writer = new Stream(ErrorHandler::ERROR_PATH); $logger = new Logger(); $logger->addWriter($writer); $logger->info($message . "\r\r"); return false; }
/** * To Log all activities relating to Authentication * @author James * @param object $action */ public function authenticationLog($action) { $this->controler = $this->params('controller'); $this->page = $this->params('action'); $filename = date('d-m-Y'); $path = dirname(dirname(dirname(__DIR__))) . '/logs/authentication'; $writer1 = new \Zend\Log\Writer\Stream($path . '/' . $filename . '.txt'); $this->logger->addWriter($writer1); $this->logger->info('Action : [' . $action . '] User : [' . $this->session['user_id'] . '] IP : [' . $this->ip . ']' . ' Page : [' . $this->page . '] Controller: [' . $this->controler . ']'); }
/** * Output a message with a timestamp * * @param string $msg Message * @param boolean $error Log as en error message? * * @return void */ protected function msg($msg, $error = false) { $msg = '[' . getmypid() . "] {$msg}"; if ($error) { $this->errLogger->err($msg); $this->logger->err($msg); } else { $this->logger->info($msg); } }
public static function log($message) { $logger = new Logger(); $stream = @fopen(__DIR__ . '/../../logs/log_' . date('Y-m-d') . ".log", 'a', false); if (!$stream) { throw new Exception('Failed to open stream'); } $writer = new Stream($stream); $logger->addWriter($writer); $logger->info($message); }
/** * @return string */ public function cleanUpAction() { $readyQueue = $this->queueItemRepository->getSuspiciousQueue(); if ($this->isVerbose()) { if (empty($readyQueue)) { $this->logger->info('Nothing to fix.'); } else { foreach ($readyQueue as $queueItem) { $this->logger->info('Fixing queue item: ' . $this->queueItemToString($queueItem)); } } } $this->queueItemRepository->fixSuspiciousQueue($readyQueue); return ''; }
protected function saveLog($message, $filename = 'log') { $file = $filename . '_' . date('Y-m-d') . '.txt'; // $writer = new LogWS($filepath); // $logger = new Logger(); // $logger->addWriter($writer); // $logger->info($log); $logdir = 'data/log'; // check if the log dir exists if (!file_exists($logdir)) { mkdir($logdir, 0777, true); } $stream = fopen($logdir . '/' . $file, 'a', false); $writer = new Stream($stream); $logger = new Logger(); $logger->addWriter($writer); $logger->info(time() . ': ' . $message); }
public function getServiceConfig() { return ['factories' => array('Zend\\Log' => function ($sm) { $log = new Logger(); $stream_writer = new Stream('./data/log/application.log'); $log->addWriter($stream_writer); $log->info('Logging started...'); return $log; }, 'UserModel' => function (\Zend\ServiceManager\ServiceLocatorInterface $sl) { $instance = new \Application\Model\User(); $instance->setServiceLocator($sl); $instance->setRelation('addressid', 'address'); return $instance; }, 'FeedbackModel' => function (\Zend\ServiceManager\ServiceLocatorInterface $sl) { $instance = new \Netsensia\Model\Feedback(); $instance->setServiceLocator($sl); return $instance; }, 'AddressModel' => function (\Zend\ServiceManager\ServiceLocatorInterface $sl) { $instance = new \Netsensia\Model\Address(); $instance->setServiceLocator($sl); return $instance; })]; }
/** * @group ZF-8491 */ public function testLogAcceptsExtrasParameterAsScalarAndAddsAsInfoKeyToEvent() { $logger = new Logger($mock = new Log\Writer\Mock()); $logger->info('foo', 'nonesuch'); $event = array_shift($mock->events); $this->assertContains('info', array_keys($event)); $info = $event['info']; $this->assertContains('nonesuch', $info); }
/** * Drop a column if it exists * * @param \Zend\Log\Logger $logger Logger instance * @param \Nada_Database $database Database object * @param string $column column name * @codeCoverageIgnore */ protected function _dropColumnIfExists($logger, $database, $column) { $tables = $database->getTables(); if (isset($tables[$this->table])) { $table = $tables[$this->table]; $columns = $table->getColumns(); if (isset($columns[$column])) { $logger->info("Dropping column {$this->table}.{$column}..."); $table->dropColumn($column); $logger->info('done.'); } } }
public function __c_write_log($doc = 'default', $filename = 'default') { if (!$this->__c_is_str() || empty($doc) || empty($filename)) { return false; } if (!file_exists($this->__c_path)) { @mkdir($this->__c_path); } $path = '/' . date('Y-m-d'); if (!file_exists($this->__c_path . $path)) { @mkdir($this->__c_path . $path); } $aSperateDocument = explode('|', $doc); foreach ($aSperateDocument as $vDoc) { $path .= '/' . $vDoc; if (!file_exists($this->__c_path . $path)) { @mkdir($this->__c_path . $path); } } $writer = new Stream($this->__c_path . $path . '/' . $filename . '.log'); $logger = new Logger(); $logger->addWriter($writer); $logger->info($this->__get_str()); }
/** * Create or update table according to schema * * @param \Zend\Log\Logger $logger Logger instance * @param array $schema Parsed table schema * @param \Nada\Database\AbstractDatabase $database Database object * @param string[] $obsoleteColumns List of obsolete columns to prune or warn about * @param bool $prune Drop obsolete tables/columns */ public static function setSchema($logger, $schema, $database, array $obsoleteColumns = array(), $prune = false) { $tableName = $schema['name']; if (in_array($tableName, $database->getTableNames())) { // Table exists // Update table and column comments $table = $database->getTable($tableName); if ($schema['comment'] != $table->getComment()) { $table->setComment($schema['comment']); } $columns = $table->getColumns(); foreach ($schema['columns'] as $column) { if (isset($columns[$column['name']])) { // Column exists. Set comment. $columnObj = $table->getColumn($column['name']); $columnObj->setComment($column['comment']); // Change datatype if different. if ($columnObj->getDatatype() != $column['type'] or $columnObj->getLength() != $column['length']) { $logger->info("Setting column {$tableName}.{$column['name']} type to {$column['type']}({$column['length']})..."); $columnObj->setDatatype($column['type'], $column['length']); $logger->info('done.'); } // Change constraints if different. if ($columnObj->getNotNull() != $column['notnull']) { $logger->info(($column['notnull'] ? 'Setting' : 'Removing') . " NOT NULL constraint on column {$tableName}.{$column['name']}..."); $columnObj->setNotNull($column['notnull']); $logger->info('done.'); } // Change default if different. // Since SQL types cannot be completely mapped to PHP // types, a loose comparision is required, but changes // to/from NULL must be taken into account. if ($columnObj->getDefault() === null and $column['default'] !== null or $columnObj->getDefault() !== null and $column['default'] === null or $columnObj->getDefault() != $column['default']) { $logger->info(sprintf("Setting default value of column {$tableName}.{$column['name']} to %s...", $column['default'] === null ? 'NULL' : "'{$column['default']}'")); $columnObj->setDefault($column['default']); $logger->info('done.'); } } else { $logger->info("Creating column {$tableName}.{$column['name']}..."); $table->addColumnObject($database->createColumnFromArray($column)); $logger->info('done.'); } } // Check for altered PK definition $primaryKey = $table->getPrimaryKey(); if ($primaryKey) { foreach ($primaryKey as &$column) { $column = $column->getName(); } unset($column); } else { $primaryKey = array(); } if ($schema['primary_key'] != $primaryKey) { $logger->info(sprintf('Changing PK of %s from (%s) to (%s)...', $tableName, implode(', ', $primaryKey), implode(', ', $schema['primary_key']))); $table->setPrimaryKey($schema['primary_key']); $logger->info('done.'); } } else { // Table does not exist, create it $logger->info("Creating table '{$tableName}'..."); $table = $database->createTable($tableName, $schema['columns'], $schema['primary_key']); $table->setComment($schema['comment']); if ($database->isMySql()) { $table->setEngine($schema['mysql']['engine']); $table->setCharset('utf8'); } $logger->info('done.'); } // Create missing indexes. Ignore name for comparision with existing indexes. if (isset($schema['indexes'])) { foreach ($schema['indexes'] as $index) { if (!$table->hasIndex($index['columns'], $index['unique'])) { $logger->info("Creating index '{$index['name']}'..."); $table->createIndex($index['name'], $index['columns'], $index['unique']); $logger->info('done.'); } } } // Detect obsolete columns that are present in the database but not in // the current schema. foreach ($obsoleteColumns as $column) { if ($prune) { $logger->notice("Dropping column {$tableName}.{$column}..."); $table->dropColumn($column); $logger->notice('done.'); } else { $logger->warn("Obsolete column {$tableName}.{$column} detected."); } } }
public function loggingAccess($request) { $logger = new Logger(); $writer = new Stream(LOG_DIR . "/access/" . date('Y-m-d')); $logger->addWriter($writer); $logger->info($request); }
/** * @return string */ public function sqlAction() { $this->logger->info("Running..."); return ''; }
/** * Log data into system.log file. * * @param $data */ public function log($data) { $this->connectorLogger->info($data); }
/** * @param string $msg * @return \Zend\Log\Logger */ public function logInfo($msg) { return $this->logger->info($msg); }