public function log($loggingLevel = 2) { if (is_writable($this->logFile)) { $message = 'Log info: '; if (!empty($this->postback)) { $message = $this->message . "\n" . "Postback info: " . serialize($this->postback) . "\n"; } $message .= "\n"; $hzl = new \Hubzero\Log\Writer(new \Monolog\Logger(Config::get('application_env')), Event::getRoot()); $hzl->useFiles($this->logFile); if ($loggingLevel == 0) { $hzl->error($this->caller . ': ' . $message); } elseif ($loggingLevel == 1) { $log = $hzl->warning($this->caller . ': ' . $message); return $log; } elseif ($loggingLevel == 2) { $log = $hzl->info($this->caller . ': ' . $message); return $log; } // If error, needs to send email to admin $this->emailError($this->message, 'POSTBACK'); } else { $this->emailError($this->logFile, 'LOG'); } }
/** * Writes the log statment out * * @return void * @since 2.0.0 **/ public static function write($statement) { $logger = new \Hubzero\Log\Writer(new \Monolog\Logger(\Config::get('application_env')), \Event::getRoot()); $path = is_dir(self::HZPATH) ? self::HZPATH : \Config::get('log_path'); $logger->useFiles($path . DS . self::FILENAME, 'info', "%datetime% %message%\n", "Y-m-d\\TH:i:s.uP", 0640); $logger->info($statement); }
public function log($loggingLevel = 2) { if (!file_exists($this->logFile)) { try { Filesystem::write($this->logFile, ''); } catch (\Exception $e) { $this->emailError($this->logFile, 'NO_LOG'); } } if (is_writable($this->logFile)) { $message = 'Log info: '; $message .= $this->message; if (!empty($this->postback)) { $message .= "\n" . "Postback info: " . serialize($this->postback) . "\n"; } $message .= "\n"; $hzl = new \Hubzero\Log\Writer(new \Monolog\Logger(Config::get('application_env')), \JDispatcher::getInstance()); $hzl->useFiles($this->logFile); if ($loggingLevel == 0) { $hzl->error($this->caller . ': ' . $message); } elseif ($loggingLevel == 1) { $log = $hzl->warning($this->caller . ': ' . $message); return $log; } elseif ($loggingLevel == 2) { $log = $hzl->info($this->caller . ': ' . $message); return $log; } // If error, needs to send email to admin $this->emailError($this->message, 'POSTBACK'); } else { $this->emailError($this->logFile, 'LOG'); } }
public function log() { // <timstamp> <hubname> <ip-address> <app> <url> <query> <memory> <querycount> <timeinqueries> <totaltime> // This method is only called once per request so we don't need to // seperate logger instance creation from its use $logger = new \Hubzero\Log\Writer(new \Monolog\Logger(\JFactory::getConfig()->getValue('config.application_env')), \JDispatcher::getInstance()); $path = \JFactory::getConfig()->getValue('config.log_path'); if (is_dir('/var/log/hubzero-cms')) { $path = '/var/log/hubzero-cms'; } $logger->useFiles($path . '/cmsprofile.log', 'info', "%datetime% %message%\n", "Y-m-d\\TH:i:s.uP", 0640); $hubname = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'unknown'; $uri = JURI::getInstance()->getPath(); $uri = strtr($uri, array(" " => "%20")); $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'unknown'; $query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : 'unknown'; $memory = memory_get_usage(true); $db = \JFactory::getDBO(); $querycount = $db->getCount(); $querytime = $db->timer; $client = \JApplicationHelper::getClientInfo(\JFactory::getApplication()->getClientId())->name; $time = microtime(true) - $this->_start; $logger->info("{$hubname} {$ip} {$client} {$uri} [{$query}] {$memory} {$querycount} {$querytime} {$time}"); }