由于公司使用的 SAP 服务器,不允许远程调试,只让在服务器上面通过看日志的方式,来观察服务器数据(哎,从来没有做过不让 debug 的项目,从来没做过只让 jdk32 位才能开发的项目)。我的前任 SAP 开发人员,要抛异常的方式来看服务器上面的数据,回来发现没部署一次 SAP 服务器花费的时间特别久,我就在寻找有没有其他方式,就这样我找到使用 SAP 的 log API 来完成。
定义成员变量:
- private static final com.sap.tc.logging.Location location = com.sap.tc.logging.Location.getLocation(xxx.class);
Note:xxx.class 是当前所在类。
使用 SimpleLogger 进行日志输出:
- SimpleLogger.log(Severity.INFO, Category.SYS_SERVER, location, "mylog", message);
Note: 这里的 message 是 java 的 String 对象,即你想要输出的查看的数据。
登录 SAP 的浏览器控制台,查看日志:
从此以后告别依靠自建异常的撮方式看数据了。
参考:
Implementing Logs in the HelloWorld Application
Viewing Logs of the HelloWorld Application
SimpleLogger Class
来源: http://www.jianshu.com/p/ffb6a18f2518