ServletContext.log() 不记录日志
使用 getServletContext().log("anything"); 时,我的 RemoteServiceServlet (GWT) 的日志输出未显示在日志文件或标准输出中;
对于依赖项注入,我使用 谷歌Guice。对于我自己的日志输出,我使用 slf4j-jdk14。我在 Tomcat 6 和 Jetty(GWT devmode)中尝试过。
说清楚一点,我的Servlet:
@Singleton
public class MyServiceServlet extends RemoteServiceServlet implements MyService {
private static final Logger log = LoggerFactory.getLogger(MyServiceServlet.class);
private final ADependency dep;
@Inject
public MyServiceServlet(ADependency dep) {
getServletContext().log("THIS IS NOT SHOWN IN MY LOGS");
log.error("THIS IS SHOWN IN MY LOGS");
this.dep = dep;
}
}
那么,我在哪里可以找到丢失的日志输出或者在哪里可以配置ServletContext-Log?
Log output of my RemoteServiceServlet
(GWT) is not shown in Logfiles or Stdout when using getServletContext().log("anything");
For dependency injection I use Google Guice. For my own log output I use slf4j-jdk14. I tried this in Tomcat 6 as well as in Jetty (GWT devmode).
To make it clear, my Servlet:
@Singleton
public class MyServiceServlet extends RemoteServiceServlet implements MyService {
private static final Logger log = LoggerFactory.getLogger(MyServiceServlet.class);
private final ADependency dep;
@Inject
public MyServiceServlet(ADependency dep) {
getServletContext().log("THIS IS NOT SHOWN IN MY LOGS");
log.error("THIS IS SHOWN IN MY LOGS");
this.dep = dep;
}
}
So, where can I find the missing log output or where can I configure the ServletContext-Log?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ServletContext.log 方法行为是特定于容器的。我用来使其保持一致的方法是包装通过 init() 传入的 ServletConfig,以便创建一个包装的 ServletContext,它使用我们自己提供的记录器(在本例中为 Slf4j)。
完整的 Slf4jServletConfigWrapper.java 代码
在您的 Servlet 中重写 init() 方法以使用 ServletConfig 包装器
The ServletContext.log method behavior is container specific. The method I have used to make it consistent is to wrap the ServletConfig passed in through init() in order to create a wrapped ServletContext which uses our own provided logger (Slf4j in this case).
Full Slf4jServletConfigWrapper.java code
In your Servlet override the init() method to use the ServletConfig wrapper