如何让Jetty打印日志
我的项目运行在 Wicket+Spring+JPA/Hibernate 上。当我使用以下命令运行它时:
mvn jetty:run
我希望 jetty 打印我在代码中生成的日志。例如,我实现了以下 DAO:
@Repository(value = "isinDao")
public class IsinDaoJpa implements IsinDao {
@PersistenceContext
private EntityManager em;
private static Logger logger = LoggerFactory.getLogger(IsinDaoJpa.class);
public Isin findById(Long id) {
return em.find(Isin.class, id);
}
public List findAll() {
Query query = em.createQuery("select e from Isin e");
logger.info("DAO: All ISINs selected");
return query.getResultList();
}
}
How do I make Jetty print this information real-time into the command line window?
在 pom.xml 中,我有以下依赖项:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
My project runs on Wicket+Spring+JPA/Hibernate. When I run it using the command:
mvn jetty:run
I'd like jetty to print logs I make in the code. I have for example the following DAO implemented:
@Repository(value = "isinDao")
public class IsinDaoJpa implements IsinDao {
@PersistenceContext
private EntityManager em;
private static Logger logger = LoggerFactory.getLogger(IsinDaoJpa.class);
public Isin findById(Long id) {
return em.find(Isin.class, id);
}
public List findAll() {
Query query = em.createQuery("select e from Isin e");
logger.info("DAO: All ISINs selected");
return query.getResultList();
}
}
How do I make Jetty print this information real-time into the command line window?
In pom.xml, I have the following dependencies:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您使用 SLF4-to-log4j 桥接器,因此需要在 log4j 配置中配置日志记录。
要使用 Spring 配置 log4j 日志记录,您需要将以下内容添加到
web.xml
(在ContextLoaderListener
之前):然后在
/WEB-INF/log4j.xml 中配置 log4j
(您也可以使用传统的log4j.properties
):另请参阅:
Since you use SLF4-to-log4j bridge, you need to configure logging in log4j configuration.
To configure log4j logging with Spring you need to add the following to
web.xml
(beforeContextLoaderListener
):Then configure log4j in
/WEB-INF/log4j.xml
(you may also use traditionallog4j.properties
):See also: