gpt4 book ai didi

java - 如何使用 BasicConfigurator 设置文件位置

转载 作者:行者123 更新时间:2023-12-01 14:30:33 24 4
gpt4 key购买 nike

我正在尝试将我的应用程序配置为不使用 log4j.properties,而是使用 BasicConfigurator 来配置 log4j.properties 中的所有内容>。我不知道如何设置文件的位置我尝试过,但没有成功。

Logger log = Logger.getLogger(pjp.getSignature().getDeclaringTypeName());
PatternLayout layout = new PatternLayout();
FileAppender familyservices = new FileAppender();

familyservices.setLayout(layout);
familyservices.setName("com.cambiahealth.engine.rest.family");
familyservices.setFile("/usr/regence/logs/datasvc/v1.0/familyservice.log");
log.addAppender(familyservices);

BasicConfigurator.configure(familyservices);

最佳答案

ConsoleAppender console = new ConsoleAppender(); //create appender
//configure the appender
String PATTERN = "%d [%p|%c|%C{1}] %m%n";
console.setLayout(new PatternLayout(PATTERN));
console.setThreshold(Level.FATAL);
console.activateOptions();
//add appender to any Logger (here is root)
Logger.getRootLogger().addAppender(console);

FileAppender fa = new FileAppender();
fa.setName("FileLogger");
fa.setFile("mylog.log");
fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
fa.setThreshold(Level.DEBUG);
fa.setAppend(true);
fa.activateOptions();

/add appender to any Logger (here is root)
Logger.getRootLogger().addAppender(fa)
//repeat with all other desired appenders

关于java - 如何使用 BasicConfigurator 设置文件位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16884256/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com