在/opt/lampp/vhosts/development.com/htdocs/test/Monolog/Logger.php中找不到接口'Psr \ Log \ LoggerInterface'

时间:2013-12-23 07:37:59

标签: php logging monolog

我正在尝试执行monolog的基本示例。我试过以下代码。

我的index.php文件是

 <?php
        include_once __DIR__ . '/Psr/Log/LoggerInterface';
        include_once __DIR__ . '/Psr/Log/AbstractLogger';
        include_once __DIR__ . '/Psr/Log/LogLevel';
        include_once __DIR__ . '/Psr/Log/InvalidArgumentException';
        include_once __DIR__ . '/Monolog/Logger.php';
        include_once __DIR__ . '/Monolog/Handler/HandlerInterface.php';
        include_once __DIR__ . '/Monolog/Handler/AbstractHandler.php';
        include_once __DIR__ . '/Monolog/Handler/AbstractProcessingHandler.php';
        include_once __DIR__ . '/Monolog/Handler/StreamHandler.php';

        include_once __DIR__ . '/Monolog/Formatter/FormatterInterface.php';
        include_once __DIR__ . '/Monolog/Formatter/NormalizerFormatter.php';
        include_once __DIR__ . '/Monolog/Formatter/LineFormatter.php';
        use Monolog\Logger;
        use Monolog\Handler\StreamHandler;

        $logger = new Logger("my_name");
        $logger->pushHandler(new StreamHandler("test_log.log", Logger::DEBUG));

        $log->addWarning('Foo');
        $log->addError('Bar');
    ?>

我收到以下错误

Fatal error: Interface 'Psr\Log\LoggerInterface' not found in /opt/lampp/vhosts/development.com/htdocs/test/Monolog/Logger.php on line 28

我的文件夹结构是

/opt/lampp/vhosts/development.com/htdocs/test
/opt/lampp/vhosts/development.com/htdocs/test/Monolog
/opt/lampp/vhosts/development.com/htdocs/test/Psr
/opt/lampp/vhosts/development.com/htdocs/test/index.php
你能告诉我这个吗?提前谢谢。

2 个答案:

答案 0 :(得分:2)

如果您不使用自动加载器,那么您也必须include_once每个依赖项。

答案 1 :(得分:0)

在主文件夹中安装了composer.phar文件。

$php composer.phar install