Example #1
0
 public function testMain()
 {
     $logger = new Logger();
     $this->assertFalse($logger->hasLogs(), 'has logs is false');
     $logger->add('Start log');
     $this->assertContains('Start log', $logger->getLast(), 'getLast default log');
     $this->assertCount(1, $logger->getList(), 'getList count is one');
     $this->assertTrue($logger->hasLogs(), 'has logs is true');
     $logger->add('executing', Logger::NAMESPACE_DB);
     $this->assertArrayHasKey(Logger::NAMESPACE_DB, $logger->getListWithNamespaces(), 'db record added');
     $this->assertEquals('', $logger->getLogsPath(), 'Log folder is empty');
     $logsPath = __DIR__ . '/tmp/';
     $logger->setLogsPath($logsPath);
     $this->assertEquals($logsPath, $logger->getLogsPath(), 'Log folder set');
     $logger->save();
     $this->assertFileExists($logsPath . Logger::NAMESPACE_APPLICATION . '.log', 'application.txt created');
 }
Example #2
0
 /**
  * @param $type
  * @param $message
  * @param array $context
  * action
  */
 public function log($type, $message, array $context = NULL)
 {
     $logger = new Logger();
     if ($this->_usebeanstalk) {
         //check beanstalk connect
         try {
             $this->_dependencyInjector['beanstalk']->connect();
         } catch (Exception $err) {
             $this->_usebeanstalk = 0;
         }
     }
     if ($this->_usebeanstalk) {
         //USE BEANSTALK QUEUE
         $logcontext = array('controll' => $context['controll'], 'action' => $context['action'] . 'manager', 'username' => $context['username'], 'deltype' => isset($context['deltype']) ? $context['deltype'] : 0, 'results' => isset($context['results']) ? $context['results'] : 0, 'updatetime' => date('Y-m-d H:i:s'));
         $arr = array('username' => $context['username'], 'msg' => $message, 'loggerlist' => $logcontext);
         $json_arr = json_encode($arr);
         $this->_dependencyInjector['beanstalk']->putInTube('addLogger', $json_arr, array('delay' => 2));
         return true;
     } else {
         $logger->controll = $context['controll'];
         $logger->action = $context['action'];
         $logger->results = isset($context['results']) ? $context['results'] : 0;
         $logger->username = $context['username'];
         $logger->deltype = isset($context['deltype']) ? $context['deltype'] : 0;
         $logger->updatetime = date('Y-m-d H:i:s');
         $logger->msg = $message;
         if (!$logger->save()) {
             $message = ' add log error:' . $message . '|' . join('|', $context);
             $logger = new \Phalcon\Logger\Adapter\File("../app/logs/error.log");
             $logger->log($message);
             return false;
         } else {
             return true;
         }
     }
 }
Example #3
0
/**
 *
 * register_shutdown_function脚本终止前回调函数
 *
 * @author          mrmsl <msl-138@163.com>
 * @date            2012-09-12 13:25:24
 * @lastmodify      2013-01-22 17:15:52 by mrmsl
 *
 * @return void 无返回值
 */
function fatal_error()
{
    Logger::save();
    //session_write_close();//必须
    if ($e = error_get_last()) {
        error_handler($e['type'], $e['message'], $e['file'], $e['line']);
    }
}
Example #4
0
 /**
  * 关闭处理
  */
 public static function _shutdown()
 {
     // 判断是否存在错误,存在则写入Log
     if ($e = error_get_last()) {
         Logger::error("_shutdown : [{$e['type']}] {$e['message']} File: {$e['file']} Line: {$e['line']}");
     }
     Logger::save();
 }
Example #5
0
    $tests = \Nette\Utils\Finder::findFiles("*.phpt")->in($testsDir);
    $all = $failed = 0;
    foreach ($tests as $filename => $file) {
        /** @var SplFileInfo $file */
        require_once $filename;
        $testClassName = $file->getBasename("." . $file->getExtension());
        if (!class_exists($testClassName)) {
            throw new \Exception("Excepted class {$testClassName} in {$filename}.");
        }
        $class = new $testClassName();
        if (!$class instanceof BaseTest) {
            throw new \Exception("Test class {$testClassName} must inherited BaseTest.");
        }
        Tester\Assert::$onFailure = function (\Tester\AssertException $e) use($logger, $class) {
            $logger->log($class, $e);
        };
        $all++;
        try {
            $class->run($driver);
        } catch (\Exception $e) {
            $failed++;
            $logger->log($class, $e);
        }
    }
} catch (\Exception $e) {
    $logger->save($all, $failed);
    $driver->close();
    throw $e;
}
$logger->save($all, $failed);
$driver->close();
 private function saveToLog($q = '===================================')
 {
     if (!self::LOG_ENABLED) {
         return;
     }
     require_once LIB_DIR . 'Logger.class.php';
     Logger::save('mysql.log', "\n" . $_SERVER['REQUEST_URI'] . "\n" . $q . "\n" . mysql_stat() . "\n===================================\n");
 }