Java 翻译器将 println 用法转换为方便的记录器
我经常看到(并重用)没有适当输出的第三方源代码。是否有任何工具(代码翻译器)可以将 println 输出转换为合适的日志框架代码
private void processCreateTraining() {
System.out.println("Training set created");
//..
}
,例如
private void processCreateTraining() {
LOG.info("Training set created");
//..
}
可以通过 IDEA 中的搜索和替换或结构替换来完成。但是是否有更复杂/强大的解决方案可以提供更大的灵活性:不同的日志框架支持、询问发生替换的严重性、通过 StringBuilder 连接字符串。
I often see (and reuse) 3rd party source code that doesn't have appropriate output. Is there any tool (code translator) that convert println
output to suitable log framework code
private void processCreateTraining() {
System.out.println("Training set created");
//..
}
to something like
private void processCreateTraining() {
LOG.info("Training set created");
//..
}
It could be done by search-and-replace or Structural Replace in IDEA. But is there more sophisticated/robust solution that provide more flexibility: different logging framework support, ask severity on occurrence replace, string concatenation via StringBuilder
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我遇到到处使用
println
的第三方库,我往往不会使用它。这是做工不佳的标志,(对我来说)这意味着代码可能存在其他更隐蔽的问题。但不,我不知道有任何插件或工具专门处理这种情况。
If I come across third party libraries that use
println
all over the place, I tend NOT to use it. It is a sign of poor workmanship, and that implies (to me) that there are likely to be other more insidious problems with the code.But no, I'm not aware of any plugin or tool to deal specifically with this case.
当然,尝试这样的事情:
WrappedOutputStream.java
Sure, try something like this:
WrappedOutputStream.java