Log4cxx 属性文件变量替换
Log4cxx properties file variable substitution
我有一个用于 log4cxx 配置的属性文件,其变量名称为 ${name}:
属性文件示例:
log4j.rootLogger=INFO, FILE
# FILE
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=./${name}
log4j.appender.FILE.MaxFileSize=16MB
log4j.appender.FILE.MaxBackupIndex=10
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p %m%n
如何从我的 cpp 文件或 cmake 文件中设置变量 ${name}。
我尝试了以下代码,但它不起作用:
#include <log4cxx/logger.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/helpers/properties.h>
using namespace log4cxx;
static LoggerPtr logger(Logger::getLogger(""));
int main() {
PropertyConfigurator::configure("./assets/logger.properties");
#ifndef NDEBUG
logger->setLevel(log4cxx::Level::getDebug());
#endif
return EXIT_SUCCESS;
}
提前致谢
找到解决方案:使用 stdlib 中的 setenv。
这是工作解决方案:
#include <stdlib.h> // Include the library
#include <log4cxx/logger.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/helpers/properties.h>
using namespace log4cxx;
static LoggerPtr logger(Logger::getLogger(""));
int main() {
// Set the env variable
// The identifier must be the same as the one in the log4cxx configuration file
setenv("name", "NAME_OF_THE_CURRENT_LOG_FILE", true);
PropertyConfigurator::configure("./assets/logger.properties");
#ifndef NDEBUG
logger->setLevel(log4cxx::Level::getDebug());
#endif
return EXIT_SUCCESS;
}
我希望它不仅对我有用:)
我有一个用于 log4cxx 配置的属性文件,其变量名称为 ${name}:
属性文件示例:
log4j.rootLogger=INFO, FILE
# FILE
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=./${name}
log4j.appender.FILE.MaxFileSize=16MB
log4j.appender.FILE.MaxBackupIndex=10
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p %m%n
如何从我的 cpp 文件或 cmake 文件中设置变量 ${name}。 我尝试了以下代码,但它不起作用:
#include <log4cxx/logger.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/helpers/properties.h>
using namespace log4cxx;
static LoggerPtr logger(Logger::getLogger(""));
int main() {
PropertyConfigurator::configure("./assets/logger.properties");
#ifndef NDEBUG
logger->setLevel(log4cxx::Level::getDebug());
#endif
return EXIT_SUCCESS;
}
提前致谢
找到解决方案:使用 stdlib 中的 setenv。 这是工作解决方案:
#include <stdlib.h> // Include the library
#include <log4cxx/logger.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/helpers/properties.h>
using namespace log4cxx;
static LoggerPtr logger(Logger::getLogger(""));
int main() {
// Set the env variable
// The identifier must be the same as the one in the log4cxx configuration file
setenv("name", "NAME_OF_THE_CURRENT_LOG_FILE", true);
PropertyConfigurator::configure("./assets/logger.properties");
#ifndef NDEBUG
logger->setLevel(log4cxx::Level::getDebug());
#endif
return EXIT_SUCCESS;
}
我希望它不仅对我有用:)