Seam3 焊料记录
我刚刚开始使用 Seam Solder,他们的日志记录模块看起来很有趣 http://docs.jboss.org/seam/3/solder/latest/reference/en-US/html/logging.html
请参阅帖子底部的代码以获取我的测试示例。
尝试使用它时出现了一些问题:
- 如何注入普通的 log4j Logger 对象?文档只有 @Inject Logger log ,看起来很简单,但是在部署时抛出异常: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependency for type [Logger] 在注入点 [[field] @Inject com.company.application.controller.SessionController.log] 处带有限定符 [@Default]
- 除了来自注入一个普通的记录器,类型记录器看起来也很漂亮。该文档声称您应该使用
@LogMessage
注释,但该注释并不存在。我的猜测是它被重命名为@Log
因为这似乎有效。要启用所有常规方法(信息、警告、错误等),让日志接口扩展 BasicLogger 似乎很简单,但是这个接口似乎没有正确注释,所以实际上什么都没有调用这些方法时记录(调用处理程序检查@Message
注释并找不到)。我做错了什么还是框架真的还没有完成?当开发几个月后投入生产的系统时,我是否应该坚持使用普通的 log4j ?
接口
@MessageLogger
public interface SessionLogger extends BasicLogger{
@Message("User %s logged in. Redirecting to %s.")
@Log(level= Level.INFO)
void login(String username, String to);
@Message("User %s logged out.")
void logout(String username);
}
使用
@Inject SessionLogger log
...
log.login("username", "url");
I've just started using Seam Solder and their logging module looks interesting http://docs.jboss.org/seam/3/solder/latest/reference/en-US/html/logging.html
See code at bottom of post for my test example.
A few issues that has risen from trying to use it:
- How to inject a normal log4j Logger object? The documentation just has
@Inject Logger log
, which seems simple enough, but it throws an exception at deploy time:org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Logger] with qualifiers [@Default] at injection point [[field] @Inject com.company.application.controller.SessionController.log]
- Besides from injecting a normal logger, Typed loggers also seemed pretty nifty. The documentation claims you should use the
@LogMessage
annotation, which does not exist. My guess is that it was renamed to@Log
since this seems to work. To enable use of all normal methods (info, warning, error, etc), letting the log interface extendBasicLogger
seemed easy enough, but this interface doesn't seem to be annotated correctly, so nothing is actually logged when these methods are called (the invocation handler checks for@Message
annotation and finds none). Am I doing something wrong or is the framework just really unfinished? Should I perhaps stick with normal log4j when developing a system going into prod in a few months?
Interface
@MessageLogger
public interface SessionLogger extends BasicLogger{
@Message("User %s logged in. Redirecting to %s.")
@Log(level= Level.INFO)
void login(String username, String to);
@Message("User %s logged out.")
void logout(String username);
}
Usage
@Inject SessionLogger log
...
log.login("username", "url");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您所做的注释是焊接注释,而不是通用注释。
Be sure that the Annotations you are doing are the Solder Annotations, and not the generic ones.
您的问题看起来像是对 Seam Solder 中包含的类的依赖问题。您确定满足依赖性吗?
Your problem looks like a dependency problen on classes included in Seam Solder. Are you sure the dependency is satisfied ?