gpt4 book ai didi

java - Log4j PropertyConfigurator.configure() 将不接受 eclipse 中的字符串

转载 作者:行者123 更新时间:2023-12-01 14:47:29 26 4
gpt4 key购买 nike

我有一个奇怪的问题,可能很简单,但我已经在谷歌上搜索了 20 分钟,但没有解决

我正在尝试在 Eclipse 中使用 log4j。我下载了最新的 zip 并添加到我的类路径中。我通过复制教程创建了属性文件。属性文件位于我的项目的根文件夹中,名为“log4j.properties”。该文件包含

#define the console appender
log4j.appender.consoleAppender = org.apache.log4j.ConsoleAppender

# now define the layout for the appender
log4j.appender.consoleAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

# now map our console appender as a root logger, means all log messages will go to this appender
log4j.rootLogger = DEBUG, consoleAppender

我的类如下,eclipse在PropertyConfigurator.configure()行出现以下错误。该行有多个标记- 标记“log4j.properties”上存在语法错误,删除此标记- 标记语法错误,结构错误

但是 log4j 的 api 显示 propertyconfigurator 应该接受一个字符串。有什么建议么? -

package org.dnsdojo.ryanhost.GA.MuPlusOne;

import java.util.Random;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;


public class Genome
{
private static Logger logger = Logger.getLogger(Genome.class);
PropertyConfigurator.configure("log4j.properties");
byte[] genome;
Random rng = new Random();
String genomeString = "";

public Genome ( int stringLength, int motorSet )
{
genome = new byte[ stringLength * 7 * motorSet]; // stringLength depends on how many bytes you wish to have. For the arpibot this is dependant on the number of sensor readings taken
for (int i = 0; i < genome.length; i++)
{
genome[i] = (byte)rng.nextInt(2);
genomeString += genome[i];
}
logger.debug(genomeString);
}

public byte[] getGenome()
{
return genome;
}

public byte[] mutate (float mutationStep)
{
return genome; //placeholder
}

}

最佳答案

您当前在类 block 中有 PropertyConfigurator.configure,因此编译器会提示。将语句(以及其他非声明性语句)移动到方法或static初始化 block 中。

关于java - Log4j PropertyConfigurator.configure() 将不接受 eclipse 中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15278660/

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