gpt4 book ai didi

java - 如何为 Log4j 创建文件配置

转载 作者:行者123 更新时间:2023-12-02 13:09:03 25 4
gpt4 key购买 nike

当他添加到数据库中时我想要记录对象:

Queue<Proposal> proposals = ...;

log.info(proposals.peek());

channelToDatabase.ingection(proposals.poll());

我的提案对象:

public class Proposal {
/**
* Header of Proposal.
*/
private String header;
/**
* Author of Proposal.
*/
private String author;
/**
* Create date of Proposal.
*/
private Timestamp create;
/**
* Link to Proposal page.
*/
private String ulrPropose;
/**
* Account recruiter.
*/
private String urlRecruiter;

public String getHeader() {
return header;
}

public void setHeader(String header) {
this.header = header;
}

public String getNickname() {
return author;
}

public void setNickname(String author) {
this.author = author;
}

public Timestamp getCreateTime() {
return create;
}

public void setCreate(Timestamp create) {
this.create = create;
}

public String getUlrPropose() {
return ulrPropose;
}

public void setUlrPropose(String ulrPropose) {
this.ulrPropose = ulrPropose;
}

public String getUrlRecruiter() {
return urlRecruiter;
}

public void setUrlRecruiter(String urlRecruiter) {
this.urlRecruiter = urlRecruiter;
}

@Override
public String toString() {
return "Proposal{" +
"header='" + header + '\'' +
", author='" + author + '\'' +
", create=" + create +
", ulrPropose='" + ulrPropose + '\'' +
", urlRecruiter='" + urlRecruiter + '\'' +
'}';
}
}

我想在我的信息日志中获取如下内容:

header, ulrPropose, time_addition, nickname, author, urlRecruiter

类似于从我的数据库中选择但在日志中。

为此我需要配置文件log4j.properties。请帮助我。

最佳答案

其实和log4j关系不大。

您应该修改的是 toString() 函数 Proposal ,将其更改为您想要的格式。像这样:

return header + "," + author ...

而且你可以在网上随意选择一个log4j.properties,就可以了。只需记住仅使用“%m%n”更改 ConversionPattern,这样您就不会获得不必要的信息。

关于java - 如何为 Log4j 创建文件配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44037007/

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