Search code examples
phpcomposer-phpmonolog

using USE and Namespace (composer)in sample php file


I have sample PHP file, i run composer install and got Monolog library. when I trying their installation guide I get error 500.

When I put the following code in sample file I get error 500 on new Logger row. Maybe I have autoloader? Is it possible to use without it?

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));

// add records to the log
$log->warning('Foo');
$log->error('Bar');

Solution

  • using autoloader fixed that used that solution : https://github.com/Nilpo/autoloader/blob/master/Autoloader.php