/** * Logs with an arbitrary level. * * @param mixed $level PSR-3 log level constant, or equivalent string * @param string $message Message to log, may contain a { placeholder } * @param array $context Variables to replace { placeholder } * @return null */ public function log($level, $message, array $context = array()) { parent::log($level, $message, $context); // if we have a stack context which is the Exception that was thrown, // send that to SS_Log so writers can use that for reporting the error. if (!empty($context['stack'])) { SS_Log::log($context['stack'], $this->convertLevel($level)); } }
/** * Look for any workers which should be running on this server and if * they're not, remove them from Redis. * * This is a form of garbage collection to handle cases where the * server may have been killed and the Resque workers did not die gracefully * and therefore leave state information in Redis. */ public function pruneDeadWorkers() { $workerPids = $this->workerPids(); $workers = self::all(); foreach ($workers as $worker) { if (is_object($worker)) { list($host, $pid, $queues) = explode(':', (string) $worker, 3); if ($host != $this->hostname || in_array($pid, $workerPids) || $pid == getmypid()) { continue; } $this->logger->log(Psr\Log\LogLevel::INFO, 'Pruning dead worker: {worker}', array('worker' => (string) $worker)); $worker->unregisterWorker(); } } }
/** * Logs with an arbitrary level. * * @param mixed $level PSR-3 log level constant, or equivalent string * @param string $message Message to log, may contain a { placeholder } * @param array $context Variables to replace { placeholder } * @return null */ public function log($level, $message, array $context = array()) { if ($this->verbose) { if (!file_exists($this->filePath)) { parent::log($level, $message, $context); return; } file_put_contents($this->filePath, '[' . $level . '] [' . strftime('%T %Y-%m-%d') . '] ' . $this->interpolate($message, $context) . PHP_EOL, FILE_APPEND); return; } if (!($level === \Psr\Log\LogLevel::INFO || $level === \Psr\Log\LogLevel::DEBUG)) { if (!file_exists($this->filePath)) { parent::log($level, $message, $context); return; } file_put_contents($this->filePath, '[' . $level . '] ' . $this->interpolate($message, $context) . PHP_EOL, FILE_APPEND); return; } }