I am having this code to execute in a local host and I am using wamp server for php5.3 x64 bit and I am unable to execute this code and I am very new to php.
Is there any code changes or any additions to this code?
My file name is monolog_usage_1.php
and I copied monolog file in src
of https://github.com/Seldaek/monolog downloaded one to the same directory.
use \Monolog\Logger;
use \Monolog\Handler\StreamHandler;
include '\Monolog\Logger.php';
// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('D:\addlog.log', Logger::WARNING));
// add records to the log
What I pass as the name To the logger('name'), is it any method name like ERROR, ALERT... Thanks in advance..
The error is explicit Class 'Monolog\Logger' not found in C:\wamp\www\test\monolog\monolog usage.php
When using Monolog you need to include all need class with full path
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;
// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler(__DIR__ . '/test/data.log', Logger::WARNING));
// add records to the log
$log->addWarning('Foo');
$log->addError('Bar');