Question

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..

Was it helpful?

Solution

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');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top