我在配置 log4php 时遇到问题,我不知道在哪里查看文档。我有这个配置:
Logger::configure(array(
'rootLogger' => array(
'level' => 'INFO',
'appenders' => array('info'),
),
'loggers' => array(
'debug' => array(
'level' => 'DEBUG',
'appenders' => array('debug'),
'additivity' => false
),
'error' => array(
'level' => 'ERROR',
'appenders' => array('error'),
'additivity' => false
)
),
'appenders' => array(
'info' => array(
'class' => 'LoggerAppenderDailyFile',
'layout' => array(
'class' => 'LoggerLayoutPattern',
'params' => array(
'conversionPattern' => '%date %logger %-5level %msg%n'
)
),
'params' => array(
'datePattern' => 'Y-m-d',
'file' => '../log/ilias-info-%s.log',
'append' => true
),
'filters' => array(
'class' => 'LoggerFilterLevelRange',
'params' => array(
'levelMin' => 'info',
'levelMax' => 'info',
)
)
),
'debug' => array(
'class' => 'LoggerAppenderDailyFile',
'layout' => array(
'class' => 'LoggerLayoutPattern',
'params' => array(
'conversionPattern' => '%date %logger %-5level %msg%n'
)
),
'params' => array(
'datePattern' => 'Y-m-d',
'file' => '../log/ilias-debug-%s.log',
'append' => true
),
'filters' => array(
'class' => 'LoggerFilterLevelRange',
'params' => array(
'levelMin' => 'debug',
'levelMax' => 'debug',
)
)
),
'error' => array(
'class' => 'LoggerAppenderDailyFile',
'layout' => array(
'class' => 'LoggerLayoutPattern',
'params' => array(
'conversionPattern' => '%date %logger %-5level %msg%n'
)
),
'params' => array(
'datePattern' => 'Y-m-d',
'file' => '../log/ilias-error-%s.log',
'append' => true
),
'filters' => array(
'class' => 'LoggerFilterLevelRange',
'params' => array(
'levelMin' => 'error',
'levelMax' => 'error',
)
)
)
)
));
用法:我定义一次
$logger = Logger::getLogger(basename(__FILE__));
然后我记录我需要的东西:
$logger->info("INFO");
$logger->debug("DEBUG");
$logger->error("ERROR");
但只创建信息的日志文件。我使用 PHP 方式来配置记录器,因为对我来说这似乎是最简单的方式,但是没有很多关于这种方式的文档。我究竟做错了什么?