一个web系统调用一个jar包,如何写日志

killxj2shit 2017-12-01 04:24:38
我写了一个java项目,打成jar包给别人web项目用,我自己用的log4j,别人用的slf4j,我本来相抛异常,可有的地方抛不出去,如下,有没有办法抛出去?如果不能,我这里的logger写的日志,web项目也写日志,那不是要log4j和slf4j,两个配置文件?能不能只有一个?



public class Qustion {
jarLooger = ....;
public static void main(String[] args) throws IOException {
Files.walkFileTree(Paths.get("c:\\dir1"),
new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
// TODO
try {
thirdPartyMethod();
} catch (Exception e) {
// we don`t want to catch but throw,cause we need the caller to log it.
e.printStackTrace();
jarLooger.info();
}
return super.visitFile(file, attrs);
}
});
}

public static void thirdPartyMethod () throws Exception{
throw new Exception("third party exception");
}
}

...全文
149 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
dong_19890208 2017-12-01
  • 打赏
  • 举报
回复
个人理解,slf4j是标准,log4j实现了slf4j,所以如果开发公共jar包建议用slf4j

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧