我有这个代码在本地主机执行,我使用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 ...... 提前谢谢..
答案 0 :(得分: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');