问题描述
Google guice 具有内置记录器绑定.但是如果我想使用 commons-logging 或 log4j 记录器怎么办?
Google guice has a built-in logger binding. But what if I want to use a commons-logging or log4j logger?
我可以得到 guice 来注入一个由
Can I get guice to inject a Log created by
LogFactory.getLog(CLASS.class)
但具有与内置绑定相同的行为:
But having the same behavior as in built-in binding:
绑定会自动将记录器的名称设置为将记录器注入到其中的类的名称..
它甚至有意义吗?还是喊我干脆用内置的java Logger?或者只是使用 commons-logging 而不注入?
Does it even makes sense? Or shout I simply use the built-in java Logger? Or just use commons-logging without injections?
推荐答案
CustomInjections Guice wiki 上的页面准确地描述了如何注入一个以被注入的类命名的记录器.
The CustomInjections page on the Guice wiki describes exactly how to inject a logger named by the class it's being injected into.
这篇关于我如何让 google guice 注入自定义记录器,例如 commons-logging 或 log4j 记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!