2013-12-23 30 views
0

我試圖執行monolog的基本示例。我曾嘗試follwing代碼。在/opt/lampp/vhosts/development.com/htdocs/test/Monolog/Logger.php中找不到接口'Psr Log LoggerInterface'

我的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 

請您建議我這件事。提前致謝。

+0

對於這個PSR文件我得到以下錯誤警告:include_once(/opt/lampp/vhosts/development.com/htdocs/test/Psr/Log/LoggerInterface):未能打開流:沒有這樣的文件或目錄第2行的/opt/lampp/vhosts/development.com/htdocs/test/index.php –

+0

現代組件/庫設計爲通過自動加載機制加載。看看作曲家,作曲家是一個自動加載器的依賴管理器。無需自動加載處理這些組件將是一次漫長的旅程。 – tr0y

+0

是的,我已經完成了作曲家。謝謝@ tr0y –

回答

0

在主文件夾中安裝了composer.phar文件。

$php composer.phar install 
2

如果您不使用自動加載器,那麼您也必須使用include_once每個依賴項。

+0

是的,我沒有使用自動加載器,這就是爲什麼我在這裏包含所有文件。 –

+0

我已經完成了作曲家。謝謝。 –