예제 #1
0
파일: LogUtils.php 프로젝트: komagata/plnet
 function initialize()
 {
     $logManager =& LogManager::getInstance();
     // default logger
     $defaultLogger =& LogManager::getLogger();
     $defaultLogger->setPriority(LEVEL_WARN);
     $defaultLogger->setExitPriority(LEVEL_FATAL);
     $layout =& new PatternLayout('%N [%d] %m in %f on line %l%n');
     $fileAppender =& new FileAppender($layout, LOG_DIR . '%d{ymd}.log');
     $defaultLogger->addAppender('file', $fileAppender);
     set_error_handler(array(&$defaultLogger, 'standard'));
     // debug logger
     $debugLogger =& new Logger();
     $debugLogger->setPriority(LEVEL_DEBUG);
     $debugLogger->setExitPriority(LEVEL_FATAL);
     $simpleLayout =& new PatternLayout('%N [%d] %m%n');
     $fileAppender =& new FileAppender($simpleLayout, LOG_DIR . 'debug_%d{ymd}.log');
     $debugLogger->addAppender('file', $fileAppender);
     $stdoutAppender =& new StdoutAppender($simpleLayout);
     $debugLogger->addAppender('stdout', $stdoutAppender);
     $logManager->addLogger('debuglogger', $debugLogger);
     if (MOJAVI_ENV == 'production') {
         $defaultLogger->removeAppender('stdout');
         $debugLogger->removeAppender('stdout');
         $smtpAppender =& new SMTPAppender($layout, PLNET_ERROR_MAIL_TO, '*****@*****.**', 'Plnet Error');
         $defaultLogger->addAppender('smtp', $smtpAppender);
     } else {
         if (isset($_SERVER['REQUEST_URI'])) {
             $debugLogger->removeAppender('stdout');
         }
     }
 }
예제 #2
0
 /**
  * Primary method to handle logging.
  *
  * @param mixed   $message  String or Exception object containing the message to log.
  * @param integer $severity The numeric severity.  Defaults to null so that no
  *                                assumptions are made about the logging backend.
  */
 public function log($message, $severity = null)
 {
     if (is_null($this->logger)) {
         $this->logger = LogManager::getLogger('propel');
     }
     switch ($severity) {
         case 'crit':
             $method = 'fatal';
             break;
         case 'err':
             $method = 'error';
             break;
         case 'alert':
         case 'warning':
             $method = 'warning';
             break;
         case 'notice':
         case 'info':
             $method = 'info';
             break;
         case 'debug':
         default:
             $method = 'debug';
     }
     // get a backtrace to pass class, function, file, & line to Mojavi logger
     $trace = debug_backtrace();
     // call the appropriate Mojavi logger method
     $this->logger->{$method}($message, $trace[2]['class'], $trace[2]['function'], $trace[1]['file'], $trace[1]['line']);
 }
예제 #3
0
 function dispatch($modName = NULL, $actName = NULL)
 {
     $logger =& LogManager::getLogger();
     set_error_handler(array(&$logger, 'standard'));
     if ($this->user === NULL) {
         $this->user =& new User();
     }
     if (USE_SESSIONS) {
         if ($this->sessionHandler !== NULL) {
             session_set_save_handler(array(&$this->sessionHandler, 'open'), array(&$this->sessionHandler, 'close'), array(&$this->sessionHandler, 'read'), array(&$this->sessionHandler, 'write'), array(&$this->sessionHandler, 'destroy'), array(&$this->sessionHandler, 'gc'));
         }
         if ($this->user->getContainer() == NULL) {
             $this->user->setContainer(new SessionContainer());
         }
     }
     $this->user->load();
     $mojavi =& $this->mojavi;
     $request =& $this->request;
     if ($modName == NULL && !$request->hasParameter(MODULE_ACCESSOR) && $actName == NULL && !$request->hasParameter(ACTION_ACCESSOR)) {
         $actName = DEFAULT_ACTION;
         $modName = DEFAULT_MODULE;
     } else {
         if ($modName == NULL) {
             $modName = $request->getParameter(MODULE_ACCESSOR);
         }
         if ($actName == NULL) {
             $actName = $request->getParameter(ACTION_ACCESSOR);
             if ($actName == NULL) {
                 if ($this->actionExists($modName, 'Index')) {
                     $actName = 'Index';
                 }
             }
         }
     }
     $actName = preg_replace('/[^a-z0-9\\-_]+/i', '', $actName);
     $modName = preg_replace('/[^a-z0-9\\-_]+/i', '', $modName);
     $this->requestAction = $actName;
     $this->requestModule = $modName;
     $mojavi['request_action'] = $actName;
     $mojavi['request_module'] = $modName;
     $mojavi['controller_path'] = $this->getControllerPath();
     $mojavi['current_action_path'] = $this->getControllerPath($modName, $actName);
     $mojavi['current_module_path'] = $this->getControllerPath($modName);
     $mojavi['request_action_path'] = $this->getControllerPath($modName, $actName);
     $mojavi['request_module_path'] = $this->getControllerPath($modName);
     $this->forward($modName, $actName);
     $this->user->store();
     if ($this->sessionHandler !== NULL) {
         $this->sessionHandler->cleanup();
     }
     $logManager =& LogManager::getInstance();
     $logManager->cleanup();
 }