0

I am trying to execute basic example of monolog. I have tried follwing code.

My index.php file is

 <?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');
    ?>

I am getting following error

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

My folder structure is

/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

Could you please suggest me about this. Thanks in advance.

Eswara Reddy
  • 1,617
  • 1
  • 18
  • 28
  • For this Psr files I am getting following error Warning: include_once(/opt/lampp/vhosts/development.com/htdocs/test/Psr/Log/LoggerInterface): failed to open stream: No such file or directory in /opt/lampp/vhosts/development.com/htdocs/test/index.php on line 2 – Eswara Reddy Dec 23 '13 at 08:10
  • Modern components / libraries are designed to be loaded by an autoloading mechanism. Have a look at composer, composer is an dependency manager which comes with an autoloader. To handle such components without autoloading would be a long trip to hell. – nihylum Dec 23 '13 at 08:26
  • Yes I have done with composer. Thanks @tr0y – Eswara Reddy Dec 23 '13 at 11:25

2 Answers2

3

If you don't use an autoloader then you must include_once each dependency too.

Maks3w
  • 6,014
  • 6
  • 37
  • 42
0

Installed the composer.phar file in the main folder.

$php composer.phar install
Eswara Reddy
  • 1,617
  • 1
  • 18
  • 28