您好如何动态更改 log4php.properties 中的日志文件名和路径
log4php.appender.A8.File=../logs/logs.log
谢谢
2条有用的信息:
(1) user367134 之前的回答很有帮助,但是它有一个错误:在设置级别时,您不应将其设置为由 LoggerLevel::DEBUG 表示的常量整数值。您应该使用 LoggerLevel::toLevel() 函数来获取 LoggerLevel 对象。IE,
$rootlogger->setLevel(LoggerLevel::DEBUG);
应该是:
$rootlogger->setLevel(LoggerLevel::toLevel(LoggerLevel::DEBUG));
(2) 这里是一个与上面类似的例子,但有一些不同:
编码:
$rootlogger = Logger::getRootLogger();
$rootlogger->setLevel(LoggerLevel::toLevel(LoggerLevel::INFO));
$appender = new LoggerAppenderRollingFile("MyAppender");
$appender->setFile("custom_name.log", true);
$appender->setMaxBackupIndex(10);
$appender->setMaxFileSize("100MB");
$appenderlayout = new LoggerLayoutPattern();
$pattern = '%d{Y-m-d H:i:s} [%p] %c: %m (at %F line %L)%n';
$appenderlayout->setConversionPattern($pattern);
$appender->setLayout($appenderlayout);
$appender->activateOptions();
$rootlogger->removeAllAppenders();
$rootlogger->addAppender($appender);
$rootlogger->info("info");
好吧,这不是我的代码,但这里是示例代码和网站链接
require_once('log4php/Logger.php');
$rootlogger = Logger::getRootLogger();
$rootlogger->setLevel(LoggerLevel::DEBUG);
$appender = new LoggerAppenderFile("MyAppender");
$appender->setFile("mylogfile.log", true);
$appenderlayout = new LoggerLayoutTTCC();
$appender->setLayout($appenderlayout);
$appender->activateOptions();
$rootlogger->removeAllAppenders();
$rootlogger->addAppender($appender);
$rootlogger->info("info");
$rootlogger->error("error");
$rootlogger->debug("debug");
归功于“AKJOL”