【问题标题】:Phalcon logger / fileAdapter not workingPhalcon 记录器/文件适配器不工作
【发布时间】:2017-06-05 08:13:33
【问题描述】:

我正在尝试使一个记录器在 PhalconPHP 中工作以进行调试。

但是无论我尝试使用什么代码,在加载浏览器时都会出现这个错误:

Can't open log file at 'app/logs/test.log'
#0 /home/myuser/public_html/demo1/app/controllers/UsersController.php(6): Phalcon\Logger\Adapter\File->__construct('app/logs/test.l...')
#1 [internal function]: unknown()
#2 [internal function]: Phalcon\Loader->autoLoad('UsersController')
#3 [internal function]: spl_autoload_call('UsersController')
#4 [internal function]: Phalcon\Dispatcher->_dispatch()
#5 [internal function]: Phalcon\Dispatcher->dispatch()
#6 /home/myuser/public_html/demo1/public/index.php(42): Phalcon\Mvc\Application->handle()
#7 {main}

<?php

use Phalcon\Logger\Adapter\File as FileAdapter;

// Create the file logger in 'w' mode
$logger = new FileAdapter("app/logs/test.log", array(
    'mode' => 'w'
));

仅供参考:所有记录器代码都在 Phalcon 控制器中进行了测试。


$logger = new \Phalcon\Logger\Adapter\File("app/logs/test.log");

$logger->log("This is a message");
$logger->log(\Phalcon\Logger::ERROR, "This is an error");
$logger->error("This is another error");

$logger->close();

use Phalcon\Logger;
use Phalcon\Logger\Adapter\File as FileAdapter;

$logger = new FileAdapter("app/logs/test.log");

$logger->log(
    "This is a message"
);

【问题讨论】:

    标签: php logging phalcon


    【解决方案1】:

    首先,我建议不要使用相对路径,而是使用绝对路径。

    在您的情况下,绝对路径似乎是: /home/myuser/public_html/demo1/app/logs/test.log

    其次检查php用户(通常在web服务器中是www-data)是否有写入logs目录的权限(例如让www-data自己的dir日志)。

    我有时遇到的最后一件事是,当您使用 cli 时,日志文件归 shell 用户所有,然后 www-data 用户无法写入该文件。为 cli 制作不同的日志或只删除日志。

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      使用 APP_PATH

      $logger = new FileAdapter(APP_PATH.'app/logs/test.log', ['mode' => 'w']);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-14
        • 1970-01-01
        • 2013-09-01
        • 1970-01-01
        相关资源
        最近更新 更多