Log4j 适用于一个类,不适用于另一类
我正在开发一个 Spring MVC 3.0.4 webapp,而 Loggerfactroy 不适用于 HomeController.java 之外的控制器类。我像这样初始化 Logger 工厂:
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
private static final Logger logger = LoggerFactory.getLogger(RequestDataController.class);
并
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
为这两个类添加了
缺少什么配置?
I am developing a Spring MVC 3.0.4 webapp and Logger factroy doesn't work for the Controller classes other than HomeController.java. I initilize the Logger factory like:
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
private static final Logger logger = LoggerFactory.getLogger(RequestDataController.class);
and
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
is added for both classes
What configuration is missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来 SLF4J 配置错误。您将它用于自己的日志记录,这是一个正确的选择!但是Spring有硬编码的JCL日志框架。它是一个抽象层,通常使用 Log4J 实现进行配置。请访问此链接,其中有一些 JCL-to-SLF4J 掉落- 所描述的替代品。如果您想在项目中保留 Log4J 和 SLF4j,则可以将适当的日志记录首选项添加到核心 spring 包的 log4j.properties 或 log4j.xml 中。
It seems SLF4J is missconfigured. You use it for you own logging and that's a right choice! But Spring has JCL logging framework hardcoded. It's an abstarction layer that is typically configured with Log4J implementation. Please, visit this link where some JCL-to-SLF4J drop-in replacements described. If you want to leave both Log4J and SLF4j in your project than add proper logging preferences into log4j.properties or log4j.xml for core spring packages.