Exemplo n.º 1
0
 /**
  * Initialize objects for logging. We have two logs files:
  * - gid-last-request.log: to see logger for the last request
  * - gid-all-requests.log: to see all logger for all request
  *
  * @param \LoggerHierarchy Object to handle objects for logging.
  * @param mixed Either path to the config file or the configuration as
  *     an array.
  * @return void
  */
 public function configure(\LoggerHierarchy $hierarchy, $input = null)
 {
     //Create a logger layout
     $layout = new \LoggerLayoutPattern();
     $layout->setConversionPattern("%d{Y-m-d H:i:s}[%r] %-5level %C.%M[%L] %msg%n");
     $layout->activateOptions();
     // Create an appender which logs to file
     $appLog = new \LoggerAppenderRollingFile('main');
     $appLog->setFile($this->log_path . 'gid-all-requests.log');
     $appLog->setAppend(true);
     $appLog->setMaxFileSize('2MB');
     $appLog->setMaxBackupIndex(5);
     $appLog->setThreshold($this->threshold);
     $appLog->setLayout($layout);
     $appLog->activateOptions();
     //Create an appender which logs Console
     $appConsole = new \LoggerAppenderFile('console');
     $appConsole->setFile($this->log_path . 'gid-last-request.log');
     $appConsole->setAppend(false);
     $appConsole->setThreshold($this->threshold);
     $appConsole->setLayout($layout);
     $appConsole->activateOptions();
     // Add appenders to the root logger
     $root = $hierarchy->getRootLogger();
     $root->addAppender($appLog);
     $root->addAppender($appConsole);
 }
 /**
  * The File property takes a string value which should be the name of the file to append to.
  * Sets and opens the file where the log output will go.
  *
  * @see LoggerAppenderFile::setFile()
  */
 public function setFile()
 {
     $numargs = func_num_args();
     $args = func_get_args();
     if ($numargs == 1 and is_string($args[0])) {
         parent::setFile(sprintf((string) $args[0], date($this->getDatePattern())));
     } elseif ($numargs == 2 and is_string($args[0]) and is_bool($args[1])) {
         parent::setFile(sprintf((string) $args[0], date($this->getDatePattern())), $args[1]);
     }
 }
 public function testActivationDoesNotCreateTheFile()
 {
     $path = PHPUNIT_TEMP_DIR . "/doesnotexisthopefully.log";
     @unlink($path);
     $appender = new LoggerAppenderFile();
     $appender->setFile($path);
     $appender->activateOptions();
     self::assertFalse(file_exists($path));
     $event = LoggerTestHelper::getInfoEvent('bla');
     $appender->append($event);
     self::assertTrue(file_exists($path));
 }
Exemplo n.º 4
0
 /**
  * Similar to the parent method, but replaces "%s" in the file name with 
  * the current date in format specified by $datePattern. 
  *
  * @see LoggerAppenderFile::setFile()
  */
 public function setFile($file)
 {
     $date = date($this->getDatePattern());
     $file = sprintf($file, $date);
     parent::setFile(sprintf($file, $date));
 }
 public function testActualSubstituteConstants()
 {
     $a = new LoggerAppenderFile();
     $a->setFile('${PHPUNIT_TEMP_DIR}/log.txt');
     $actual = $a->getFile();
     $expected = PHPUNIT_TEMP_DIR . '/log.txt';
     self::assertSame($expected, $actual);
 }
 /**
  * Similar to the parent method, but replaces "%s" in the file name with 
  * the current date in format specified by $datePattern. 
  *
  * @see LoggerAppenderFile::setFile()
  */
 public function setFile($file)
 {
     //add by jiangli 2014-6-11
     //设置日志目录可配置
     $config =& get_config();
     $log_path_dir = $config['log_path_dir'];
     if (isset($log_path_dir) && !empty($log_path_dir)) {
         $log_path_dir = rtrim($log_path_dir, '/') . '/';
     } else {
         $log_path_dir = '';
     }
     $file = $log_path_dir . $file;
     $date = date($this->getDatePattern());
     $file = sprintf($file, $date);
     parent::setFile(sprintf($file, $date));
 }