我如何让 google guice 注入自定义记录器,例如 commons-logging 或 log4j 记录器 [英] How do I get google guice to inject a custom logger, say a commons-logging or log4j logger

查看:35
本文介绍了我如何让 google guice 注入自定义记录器,例如 commons-logging 或 log4j 记录器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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:

绑定会自动将记录器的名称设置为将记录器注入到其中的类的名称..

The binding automatically sets the logger's name to the name of the class into which the Logger is being injected..

<小时>

它甚至有意义吗?还是喊我干脆用内置的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 记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆