It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center




7年前关闭。





我要在本地主机中执行此代码,并且我将wamp服务器用于php5.3 x64位,但是我无法执行此代码,因此我对php非常陌生。
该代码有任何更改或补充吗?
我的文件名为monolog_usage_1.php
我在src中复制了monolog文件
https://github.com/Seldaek/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


我传递给记录器的名称(“名称”)是任何方法名称,例如ERROR,ALERT ...
提前致谢..

最佳答案

错误是明确的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');

10-06 12:02