本文整理汇总了PHP中Phalcon\Logger\Adapter\File::log方法的典型用法代码示例。如果您正苦于以下问题:PHP File::log方法的具体用法?PHP File::log怎么用?PHP File::log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Logger\Adapter\File
的用法示例。
在下文中一共展示了File::log方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: log
public static function log($type, $message = null, array $context = [])
{
static::$logger or static::$logger = Di::getDefault()->getShared('log');
$context['host'] = static::$hostname;
$context['request'] = fnGet($_SERVER, 'REQUEST_METHOD') . ' ' . fnGet($_SERVER, 'REQUEST_URI');
static::$logger->log($type, $message, $context);
}
示例2: 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;
};
}
示例3: 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'] . '¤cies=' . $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);
}
}
示例4: 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;
}
示例5: 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]);
}
示例6: 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);
}
示例7: 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;
}
示例8: 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');
}
}
示例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);
});
}
示例10: 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');
}
示例11: 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);
}
示例12: 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;
}
}
示例13: saveAction
public function saveAction()
{
$this->view->title = "Збереження студента";
$errors = array();
!file_exists($this->logFileName) ? $attr = array('mode' => 'w') : ($attr = array());
$logger = new FileAdapter($this->logFileName, $attr);
$manager = new \Phalcon\Mvc\Model\Transaction\Manager();
$transaction = $manager->get();
$indCode = $this->request->get("ind_code");
if ($indCode != NULL) {
$logger->log("indCode not NULL");
if ($this->request->isPost()) {
$logger->log("POST request finded");
//debug($this->request->get());
if ($this->request->get("uid") == NULL) {
$user = new \Users();
$logger->log("new User created");
} else {
$user = \Users::findFirst($this->request->get("uid"));
if (!$user) {
$logger->warning("this User is not finded!");
$user = new \Users();
$logger->log("new User created");
} else {
$logger->log("User id is " . $user->id);
}
}
$user->setTransaction($transaction);
$logger->log("Transaction started");
$user->name = $this->request->get("name");
$user->last_name = $this->request->get("last_name");
$user->second_name = $this->request->get("second_name");
$user->login = $this->request->get("login");
$user->password = MD5($this->request->get("password"));
$user->is_male = $this->request->get("is_male");
$user->is_active = 1;
$user->email = $this->request->get("email");
$user->date_registration = date('Y-m-d H:i:s');
$user->birthday = $this->request->get("birthday");
$user->address_home = $this->request->get("address_home");
$user->phome = $this->request->get("phome");
$user->pmobile = $this->request->get("pmobile");
if ($this->request->get("id") == NULL) {
$student = new \Students();
$logger->log("new Student created");
} else {
$student = \Students::findFirst($this->request->get("id"));
if (!$student) {
$logger->warning("this Student is not finded!");
$student = new \Students();
$logger->log("new Student created");
} else {
$logger->log("Student id is " . $user->id);
}
}
//добавление студента
$student->ind_code = $indCode;
if (count($this->request->get("student_education")) > 0) {
$logger->log("student educations from request count>0, so start to add its");
$studentEducations = array();
//добавление образований
$c = 0;
foreach ($this->request->get("student_education") as $educ) {
$logger->log("Educ cycle #" . $c++);
$educJSON = json_decode($educ, true);
$se = new \StudentsEducation();
if (!array_key_exists("education_child_id", $educJSON)) {
$se->education_id = $educJSON["education_id"];
} else {
$se->education_id = $educJSON["education_child_id"];
}
$se->institution = $educJSON["institution"];
$se->speciality = $educJSON["speciality"];
$se->qualify = $educJSON["qualify"];
$se->diploma_number = $educJSON["diploma_number"];
$se->diploma_date = $educJSON["diploma_date"];
$logger->log("Educ id = " . $educJSON["education_id"]);
$studentEducations[] = $se;
}
} else {
$logger->warning("No educations in request!");
$studentEducations = NULL;
}
if ($student->StudentsEducation->count() > 0) {
$logger->warning("Finded old education(s) (" . $student->StudentsEducation->count() . ") in this Student. Trying to delete all its");
$c = 0;
foreach ($student->StudentsEducation as $se) {
$logger->log("Educ delation cycle #" . $c++);
$se->delete();
}
} else {
$logger->warning("no old educations finded!");
}
$student->StudentsEducation = $studentEducations;
//debug($student->StudentsEducation);
if (count($this->request->get("student_post")) > 0) {
$logger->log("There is Posts in request");
$studentPosts = array();
//добавление должностей
$logger->log("new Posts addition");
//.........这里部分代码省略.........
示例14: initDatabase
/**
* 数据库连接
*/
protected function initDatabase()
{
$config = $this->config;
$debug = $this->debug;
if ($config->offsetExists('database') == false) {
return;
}
$this->di['db'] = function () use($config, $debug) {
if ($debug && $config->offsetExists('logger') && $config->logger->offsetExists('sqlPath')) {
$eventsManager = new EventsManager();
$path = $config->logger->sqlPath;
$path = str_replace('{{date}}', date("Ymd"), $path);
$logger = new LoggerFile($path);
//Listen all the database events
$eventsManager->attach('db', function ($event, $connection) use($logger) {
if ($event->getType() == 'beforeQuery') {
$logger->log($connection->getSQLStatement(), Logger::INFO);
}
});
$connection = new DbAdapter($config->database->toArray());
//Assign the eventsManager to the db adapter instance
$connection->setEventsManager($eventsManager);
return $connection;
} else {
return new DbAdapter($config->database->toArray());
}
};
}
示例15: commonServices
/**
* 默认服务依赖注入
*
*/
protected function commonServices()
{
$mode = $this->mode;
$di = $this->mode === 'CLI' ? new Cli() : new FactoryDefault();
// 日志
$di->set('logger', function () {
$config = load('logger');
$adapter = $config['adapter'];
$filename = $config[$adapter]['filename'];
$filedir = dirname($filename);
if (empty($config)) {
throw new \Exception('logger config Require failed');
}
if (!is_dir($filedir)) {
mkdir($filedir, 0755, true);
}
$logger = new File($filename);
$formatter = new Line(null, 'Y-m-d H:i:s');
$loglevel = config('app.loglevel');
$logger->setFormatter($formatter);
$logger->setLogLevel($loglevel ? $loglevel : \Phalcon\Logger::ERROR);
return $logger;
}, true);
$this->application->setDI($di);
// 命名空间
$di->set('dispatcher', function () use($mode) {
$dispatcher = new Dispatcher();
$dispatcher = $mode === 'CLI' ? new \Phalcon\CLI\Dispatcher() : new Dispatcher();
$bootstrap = load('bootstrap');
$default = $bootstrap['dispatcher'];
$dispatcher->setDefaultNamespace($mode === 'CLI' ? $default['cli'] : $default['default']);
return $dispatcher;
}, true);
// 路由
if ($load = load('router', null, true)) {
if ($load instanceof Router) {
$di->set('router', $load);
}
}
// 视图
$di->set('view', function () {
$view = new View();
$view->setViewsDir(APP_VIEW);
return $view;
}, true);
// 加解密
if ($config = config('crypt')) {
$di->set('crypt', function () use($config) {
$crypt = new Crypt();
$crypt->setKey($config['authkey']);
return $crypt;
}, true);
}
// 默认缓存
if ($config = config('cache')) {
$di->set('cache', function () use($config) {
$cache = null;
$adapter = strtolower($config['adapter']);
$options = $config[$adapter];
$frontend = new Data(array('lifetime' => $config['lifetime']));
switch ($adapter) {
case 'memcache':
$cache = new Memcache($frontend, $options);
break;
case 'redis':
if (empty($options['auth'])) {
unset($options['auth']);
}
$cache = new \Phalcon\Extend\Cache\Backend\Redis($frontend, $options);
break;
}
return $cache;
}, true);
}
// Cookies
if ($config = config('cookies')) {
$di->set('cookies', function () use($config) {
$cookies = new \Phalcon\Extend\Http\Response\Cookies($config);
if (!config('crypt.authkey')) {
$cookies->useEncryption(false);
}
return $cookies;
}, true);
}
// Session
if ($config = config('session')) {
$di->set('session', function () use($config) {
if (!empty($config['options'])) {
foreach ($config['options'] as $name => $value) {
ini_set("session.{$name}", $value);
}
}
$adapter = strtolower($config['adapter']);
$options = $config[$adapter];
switch ($adapter) {
case 'memcache':
//.........这里部分代码省略.........