문제

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');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top