如何动态更改log4php.properties中的日志文件名和路径
log4php.appender.A8.File = .. /日志/ logs.log
谢谢
答案 0 :(得分:2)
2条有用的信息:
(1)user367134的上一个答案很有帮助,但它有一个错误:设置级别时,不应将其设置为LoggerLevel :: DEBUG表示的常量整数值。您应该使用LoggerLevel :: toLevel()函数来获取LoggerLevel对象。 即,
$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");
答案 1 :(得分:0)
这不是我的代码,但这里是示例代码和网站链接
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”