From 4f4c5ce3ccf0370f926d75e700e8b0bd2208f3f6 Mon Sep 17 00:00:00 2001 From: Markus Warg Date: Wed, 31 Mar 2010 16:43:49 +0200 Subject: initial setup of framework code enabled features * login * crt login * top / left menu * logging * db layer --- manager/library/log/Log.php | 105 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 manager/library/log/Log.php (limited to 'manager/library/log/Log.php') diff --git a/manager/library/log/Log.php b/manager/library/log/Log.php new file mode 100644 index 0000000..8ad27b9 --- /dev/null +++ b/manager/library/log/Log.php @@ -0,0 +1,105 @@ +$instanceName; + + $this->log = new Zend_Log(); + if (isset($log_config->file) && intval($log_config->file->enabled) !== 0) { + $file_logger = new Zend_Log_Writer_Stream($log_config->file->name); + + /** + * + $format = Zend_Log_Formatter_Simple::DEFAULT_FORMAT; + $formatter = new Zend_Log_Formatter_Simple($format); + $file_logger->setFormatter($formatter); + */ + if (isset($application) && $application != '') + $this->log->setEventItem('application', $application); + $formatter = new Zend_Log_Formatter_Simple('%syslog_time% %application%[%pid%]: %priorityName%: %message%' . PHP_EOL); + $file_logger->setFormatter($formatter); + $this->log->addWriter($file_logger); + } + if (isset($log_config->syslog) && intval($log_config->syslog->enabled) !== 0) { + $param = array('facility' => $log_config->syslog->facility); + if (isset($application) && $application != '') + $param['application'] = $application; + + $sys_logger = new Zend_Log_Writer_Syslog($param); + $formatter = new Zend_Log_Formatter_Simple('%priorityName%: %message%' . PHP_EOL); + $sys_logger->setFormatter($formatter); + $this->log->addWriter($sys_logger); + } + + $filter = new Zend_Log_Filter_Priority(intval($log_config->priority)); + $this->log->addFilter($filter); + } + + /** + * get already existing instance, make new instance or throw an exception + * @param string $instanceName + * @param string $application + */ + public static function getInstance($instanceName = null, $application = null) { + if ($instanceName === null) { + if (count(self::$instances) == 0) + throw new Exception(__METHOD__ . ': expected an instance name, got none'); + return self::$instances[0]; + } + + if (!array_key_exists($instanceName, self::$instances)) { + self::$instances[$instanceName] = new Log($instanceName, $application); + } + + return self::$instances[$instanceName]; + } + + /** + * return SYSTEM_LOG for convenience + * @return Zend_Log + */ + public static function Log() { + return self::$instances[SYSTEM_LOG]->getLog(); + } + + /** + * get the Zend_Log object + * @return Zend_Log + */ + public function getLog() { + $this->log->setEventItem('pid', posix_getpid()); + $this->log->setEventItem('syslog_time', date('Y-m-d H:i:s')); + return $this->log; + } +} -- cgit v1.2.1