当前位置: 首页>>代码示例>>PHP>>正文


PHP Adapter\File类代码示例

本文整理汇总了PHP中Phalcon\Logger\Adapter\File的典型用法代码示例。如果您正苦于以下问题:PHP File类的具体用法?PHP File怎么用?PHP File使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了File类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: registerServices

 /**
  * Registers the module-only services
  *
  * @param Phalcon\DI $di
  */
 public function registerServices($di)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/config/config.php");
     $di['view']->setViewsDir(__DIR__ . '/views/');
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di['db'] = function () use($config) {
         $connection = new DbAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname));
         $eventsManager = new EventsManager();
         $logger = new FileLogger(__DIR__ . "/logs/db.log");
         //Listen all the database events
         $eventsManager->attach('db:beforeQuery', function ($event, $connection) use($logger) {
             $sqlVariables = $connection->getSQLVariables();
             if (count($sqlVariables)) {
                 $logger->log($connection->getSQLStatement() . ' ' . join(', ', $sqlVariables), Logger::INFO);
             } else {
                 $logger->log($connection->getSQLStatement(), Logger::INFO);
             }
         });
         //Assign the eventsManager to the db adapter instance
         $connection->setEventsManager($eventsManager);
         return $connection;
     };
 }
开发者ID:riquedesimone,项目名称:biko,代码行数:33,代码来源:Module.php

示例2: ratesAction

 /**
  * Import Exchange Rates
  */
 public function ratesAction()
 {
     $lock = $this->getLock('/tmp/rates-import.lock');
     if ($lock !== false) {
         $logger = new FileAdapter(realpath(__DIR__ . '/../logs') . '/rates-import.log');
         $di = \Phalcon\DI::getDefault();
         $guzzle = $di['guzzle'];
         $config = $di['config']['rates_api'];
         $url = $config['url'] . '?access_key=' . $config['access_key'] . '&currencies=' . $config['currencies'] . '&source=' . $config['source'];
         try {
             $request = $guzzle->createRequest('GET', $url);
             $response = $guzzle->send($request);
             $response = (string) $response->getBody();
             $rates = json_decode($response);
             if ($rates->success == true) {
                 foreach ($rates->quotes as $currencyCode => $exchangeRate) {
                     $currencyCode = preg_replace('/^USD/', '', $currencyCode);
                     $currency = Rate::updateRate($currencyCode, $exchangeRate);
                     if (!$currency) {
                         $logger->log('Failed to update currency : ' . $currencyCode . ' to rate: ' . $exchangeRate, \Phalcon\Logger::ERROR);
                     }
                 }
             } else {
                 $logger->log('Rates import failed : ' . $response, \Phalcon\Logger::ERROR);
             }
         } catch (Exception $e) {
             $logger->log('Rates import failed : ' . $e->getMessage(), \Phalcon\Logger::ERROR);
         }
         $this->releaseLock($lock);
     }
 }
开发者ID:ashleykleynhans,项目名称:forex,代码行数:34,代码来源:ImportTask.php

示例3: log

 /**
  * 保存日志
  * @param string $logString 日志信息
  * @param string $level 日志级别
  */
 public function log($logString, $level = 'info')
 {
     $logger = new FileLogger($this->logDir . $this->logFile);
     $lineFormatter = new LineFormatter();
     $lineFormatter->setDateFormat('Y-m-d H:i:s');
     $logger->setFormatter($lineFormatter);
     $logger->log($logString, $this->log_level[$level]);
 }
开发者ID:hongker,项目名称:Blog,代码行数:13,代码来源:BaseOperation.php

示例4: logToSyslog

 /**
  * Log error to syslog
  *
  * @param int        php error number
  * @param string    php error description
  * @param string    php file where the error occured
  * @param int        php line where the error occured
  * @return bool
  */
 public static function logToSyslog($errNo, $errStr, $errFile, $errLine)
 {
     $msg = sprintf("%s (errno: %d) in %s:%d", $errStr, $errNo, $errFile, $errLine);
     $logfile = config('config')->logger->path . date('/Ym/') . 'errors_' . date('Ymd') . '.log';
     if (!is_dir(dirname($logfile))) {
         mkdir(dirname($logfile), 0755, true);
     }
     $logger = new File($logfile);
     return $logger->log($msg, Logger::INFO);
 }
开发者ID:swordkee,项目名称:phalcon-demo,代码行数:19,代码来源:PhpError.php

示例5: registerServices

 /**
  * Registers services related to the module
  *
  * @param DiInterface $di
  */
 public function registerServices(DiInterface $di)
 {
     /**
      * Read configuration
      */
     $config = (include APP_PATH . "/apps/backend/config/config.php");
     /**
      * Setting up the view component
      */
     $di['view'] = function () use($config) {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => __DIR__ . '/cache/', 'compiledSeparator' => '_'));
             $compiler = $volt->getCompiler();
             // format number
             $compiler->addFilter('number', function ($resolvedArgs) {
                 return 'Helpers::number(' . $resolvedArgs . ');';
             });
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         return $view;
     };
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di['db'] = function () use($config) {
         $config = $config->database->toArray();
         $dbAdapter = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $config['adapter'];
         unset($config['adapter']);
         return new $dbAdapter($config);
     };
     /**
      * Logger service
      */
     $di->set('logger', function ($filename = null, $format = null) use($config) {
         $format = $format ?: $config->get('logger')->format;
         $filename = trim($filename ?: $config->get('logger')->filename, '\\/');
         $path = rtrim($config->get('logger')->path, '\\/') . DIRECTORY_SEPARATOR;
         $formatter = new FormatterLine($format, $config->get('logger')->date);
         $logger = new FileLogger($path . $filename);
         $logger->setFormatter($formatter);
         $logger->setLogLevel($config->get('logger')->logLevel);
         return $logger;
     });
     $di->set('url', function () use($config) {
         $url = new UrlResolver();
         $url->setBaseUri("/backend/");
         return $url;
     });
 }
开发者ID:vietdh85,项目名称:product-vh,代码行数:57,代码来源:Module.php

示例6: handleCardSubmitAction

 /**
  * Handle post data
  * 
  * @return type
  */
 public function handleCardSubmitAction()
 {
     $seri = $this->request->getPost('txtseri');
     $sopin = $this->request->getPost('txtpin');
     $mang = $this->request->getPost('chonmang');
     $user = $this->request->getPost('txtuser');
     $charid = $this->request->getPost('charguid');
     $chargeDescription = $this->request->getPost('txtDescription');
     if ($mang == 'MOBI') {
         $ten = "Mobifone";
     } else {
         if ($mang == 'VIETEL') {
             $ten = "Viettel";
         } else {
             if ($mang == 'GATE') {
                 $ten = "Gate";
             } else {
                 if ($mang == 'VTC') {
                     $ten = "VTC";
                 } else {
                     $ten = "Vinaphone";
                 }
             }
         }
     }
     $arrayPost = array('merchant_id' => $this->config->baokim->merchant_id, 'api_username' => $this->config->baokim->api_username, 'api_password' => $this->config->baokim->api_password, 'transaction_id' => time(), 'card_id' => $mang, 'pin_field' => $sopin, 'seri_field' => $seri, 'algo_mode' => 'hmac');
     // Prepare array post for CURL
     ksort($arrayPost);
     //mat khau di kem ma website dang kí trên B?o Kim
     $secure_code = $this->config->baokim->secure_code;
     $data_sign = hash_hmac('SHA1', implode('', $arrayPost), $secure_code);
     $arrayPost['data_sign'] = $data_sign;
     $userPwd = $this->config->baokim->CORE_API_HTTP_USR . ':' . $this->config->baokim->CORE_API_HTTP_PWD;
     // Init curl
     $curl = curl_init($this->config->baokim->restUrl);
     curl_setopt_array($curl, array(CURLOPT_POST => true, CURLOPT_HEADER => false, CURLINFO_HEADER_OUT => true, CURLOPT_TIMEOUT => 30, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HTTPAUTH => CURLAUTH_DIGEST | CURLAUTH_BASIC, CURLOPT_USERPWD => $userPwd, CURLOPT_POSTFIELDS => http_build_query($arrayPost)));
     $data = curl_exec($curl);
     $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     $result = json_decode($data, true);
     $logger = new FileAdapter($this->config->application->logFile);
     //        if ($status == 200) {
     if ($status == 401) {
         $logger->log("This is a message");
         return $this->response->redirect('index/success');
     } else {
         $errorData = sprintf("Eror: %d | User: %s | Ma The: %s | Seri: %s", $status, $user, $seri, $sopin);
         $logger->error($errorData);
         return $this->response->redirect('index');
     }
 }
开发者ID:byhbt,项目名称:napthe-baokim,代码行数:55,代码来源:IndexController.php

示例7: testLoggerFormatterNewFormatFormatsDateCorrectly

 /**
  * Tests new format logs correctly
  *
  * @author Nikos Dimopoulos <nikos@phalconphp.com>
  * @since  2012-09-17
  */
 public function testLoggerFormatterNewFormatFormatsDateCorrectly()
 {
     $fileName = newFileName('log', 'log');
     $logger = new PhTLoggerAdapterFile($this->logPath . $fileName);
     $formatter = new PhLoggerFormatterLine('%type%|%date%|%message%');
     $logger->setFormatter($formatter);
     $logger->log('Hello');
     $logger->close();
     $contents = file($this->logPath . $fileName);
     $message = explode('|', $contents[0]);
     cleanFile($this->logPath, $fileName);
     $date = new \DateTime($message[1]);
     $expected = date('Y-m-d H');
     $actual = $date->format('Y-m-d H');
     $this->assertEquals($expected, $actual, 'Date format not set properly');
 }
开发者ID:lisong,项目名称:cphalcon,代码行数:22,代码来源:FormatterTest.php

示例8: initPersistentDB

 public function initPersistentDB($di)
 {
     // Setup the database service
     $di->set('db', function () {
         $eventsManager = new EventsManager();
         $logger = new FileLogger(__DIR__ . '/' . date('Y-m-d') . '.sql.log');
         $eventsManager->attach('db', function ($event, $connection) use($logger) {
             if ($event->getType() == 'beforeQuery') {
                 $logger->info($connection->getSQLStatement());
             }
         });
         $db = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => "127.0.0.1", "username" => "root", "password" => "123456", "dbname" => "rookie", "charset" => "utf8", "persistent" => true));
         $db->setEventsManager($eventsManager);
         return $db;
     });
 }
开发者ID:abc2001x,项目名称:timer,代码行数:16,代码来源:React.php

示例9: testLoggerFormatterLineNewFormatLogsCorrectly

 /**
  * Tests new format logs correctly
  *
  * @author Nikos Dimopoulos <nikos@phalconphp.com>
  * @since  2012-09-17
  */
 public function testLoggerFormatterLineNewFormatLogsCorrectly()
 {
     $this->specify("Line formatted does not set format correctly", function () {
         $I = $this->tester;
         $fileName = $I->getNewFileName('log', 'log');
         $logger = new File($this->logPath . $fileName);
         $formatter = new Line('%type%|%date%|%message%');
         $logger->setFormatter($formatter);
         $logger->log('Hello');
         $logger->close();
         $I->amInPath($this->logPath);
         $I->openFile($fileName);
         $I->seeInThisFile(sprintf('DEBUG|%s|Hello', date('D, d M y H:i:s O')));
         $I->deleteFile($fileName);
     });
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:22,代码来源:LineTest.php

示例10: testLoggerAdapterFileRollback

 /**
  * Tests the begin/rollback
  *
  * @author Nikolaos Dimopoulos <nikos@phalconphp.com>
  * @since  2014-09-13
  */
 public function testLoggerAdapterFileRollback()
 {
     $this->specify("Logging does not contain correct number of messages before rollback", function () {
         $fileName = newFileName('log', 'log');
         $logger = new PhTLoggerAdapterFile($this->logPath . $fileName);
         $logger->log('Hello');
         $logger->close();
         $contents = file($this->logPath . $fileName);
         cleanFile($this->logPath, $fileName);
         $expected = 1;
         $actual = count($contents);
         expect($actual)->equals($expected);
     });
     $this->specify("Logging does not contain correct number of messages after rollback", function () {
         $fileName = newFileName('log', 'log');
         $logger = new PhTLoggerAdapterFile($this->logPath . $fileName);
         $logger->log('Hello');
         $logger->begin();
         $logger->log('Message 1');
         $logger->log('Message 2');
         $logger->log('Message 3');
         $logger->rollback();
         $logger->close();
         $contents = file($this->logPath . $fileName);
         cleanFile($this->logPath, $fileName);
         $expected = 1;
         $actual = count($contents);
         expect($actual)->equals($expected);
     });
 }
开发者ID:lisong,项目名称:cphalcon,代码行数:36,代码来源:TransactionTest.php

示例11: beforeException

 /**
  * This action is executed before execute any action in the application
  * @param Event $event
  * @param Dispatcher $dispatcher
  */
 public function beforeException(Event $event, MvcDispatcher $dispatcher, Exception $exception)
 {
     if ($exception instanceof DispatcherException) {
         switch ($exception->getCode()) {
             case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
             case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                 $dispatcher->forward(array('controller' => 'errors', 'action' => 'resourceNotFound'));
                 return false;
         }
     }
     $logDir = $this->config->application->logDir;
     $logger = new FileAdapter(APP_PATH . "/{$logDir}/TestZilla.log");
     $logger->log($exception->getMessage(), Logger::ERROR);
     $logger->log($exception->getTraceAsString(), Logger::ERROR);
     $dispatcher->forward(array('controller' => 'errors', 'action' => 'internalServerError'));
     return false;
 }
开发者ID:kelliany,项目名称:TestZilla,代码行数:22,代码来源:ExceptionHandlingPlugin.php

示例12: register

 public static function register(Di $di)
 {
     static::$hostname = gethostname();
     $di->remove('log');
     static::$logger = null;
     $di->setShared('log', function () {
         $filePath = storagePath('logs');
         is_dir($filePath) or mkdir($filePath, 0777, true);
         $filePath .= '/' . Config::get('app.log.file', 'phwoolcon.log');
         $logger = new File($filePath);
         $formatter = $logger->getFormatter();
         if ($formatter instanceof Line) {
             $formatter->setDateFormat('Y-m-d H:i:s');
             $formatter->setFormat('[%date%]{host}[%type%] {request} %message%');
         }
         return $logger;
     });
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:18,代码来源:Log.php

示例13: request_start_log

 /**
  * 记录起始请求日志
  * 记录成功返回true,失败或没记录日志返回false
  *
  * @return  bool
  */
 public static function request_start_log()
 {
     if (!BaseLog::isLog('debug')) {
         return false;
     }
     if (!Config::getEnv("app.request_start_log")) {
         return false;
     }
     $data = Request::nonPostParam();
     if (Config::getEnv("app.request_log_post")) {
         $data = Request::param();
     }
     $file_path = BaseLog::handle_log_file('framework', 'debug');
     $log_time = date("Y-m-d H:i:s", QP_RUN_START);
     $ip = Request::getIp();
     $router_url = \Qp\Kernel\Http\Router\QpRouter::getRouterStr();
     $prefix = "[{$log_time}] [{$ip}] [router : {$router_url}] ";
     $msg = "【请求日志】" . json_encode(['data' => $data]);
     $logger = new FileAdapter($file_path);
     $logger->setFormatter(new LineFormatter("%message%"));
     return (bool) $logger->log($prefix . $msg);
 }
开发者ID:q-phalcon,项目名称:kernel,代码行数:28,代码来源:SystemLog.php

示例14: setDB

 private function setDB()
 {
     $connection = new DatabaseConnection($this->database->toArray());
     $debug = $this->application->debug;
     if ($debug) {
         $eventsManager = new EventsManager();
         $logger = new FileLogger(__DIR__ . "/../Logs/db.log");
         //Listen all the database events
         $eventsManager->attach('db', function ($event, $connection) use($logger) {
             if ($event->getType() == 'beforeQuery') {
                 $variables = $connection->getSQLVariables();
                 if ($variables) {
                     $logger->log($connection->getSQLStatement() . ' [' . join(',', $variables) . ']', \Phalcon\Logger::INFO);
                 } else {
                     $logger->log($connection->getSQLStatement(), \Phalcon\Logger::INFO);
                 }
             }
         });
         $connection->setEventsManager($eventsManager);
     }
     return $connection;
 }
开发者ID:jeins,项目名称:Phalcon-RestApi,代码行数:22,代码来源:AppService.php

示例15: initialize

 public function initialize()
 {
     $this->_app = $this->dispatcher->getParam("app");
     // 设置时区
     ini_set("date.timezone", $this->config->setting->timezone);
     // 日志记录
     if ($this->config->setting->recordRequest) {
         if (isset($_REQUEST['_url'])) {
             $_url = $_REQUEST['_url'];
             unset($_REQUEST['_url']);
         } else {
             $_url = '/';
         }
         $log = empty($_REQUEST) ? $_url : $_url . '?' . urldecode(http_build_query($_REQUEST));
         $logger = new FileLogger(BASE_DIR . $this->config->application->logsDir . date("Ym") . '.log');
         $logger->log($log, Logger::INFO);
     }
     // 检查登录
     $this->_user_id = $this->session->get('user_id');
     if (!$this->_user_id || !$this->session->get('isLogin')) {
         header('Location:/login');
         exit;
     }
 }
开发者ID:xxtime,项目名称:phalcon,代码行数:24,代码来源:ControllerBase.php


注:本文中的Phalcon\Logger\Adapter\File类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。