2

我有这段代码要在本地主机上执行,我正在使用 wamp 服务器用于 php5.3 x64 位,我无法执行这段代码,我对 php 很陌生。此代码是否有任何代码更改或任何添加?我的文件名为 monolog_usage_1.php,我在https://github.com/Seldaek/monolog的 src 中复制了 monolog 文件,下载了一个到同一目录。

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

我作为名称传递给记录器('name'),是任何方法名称,如错误,警报......提前谢谢..

4

1 回答 1

6

错误是明确的 Class 'Monolog\Logger' not found in C:\wamp\www\test\monolog\monolog usage.php使用 Monolog 时,您需要包含所有需要的类和完整路径

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');
于 2012-10-22T10:41:17.747 回答