Java 适配器中的日志记录
improve this page | report issue概述
本教程提供在 Java 适配器中添加日志记录功能所需的代码片段。
日志记录示例
导入 java 日志记录包:
import java.util.logging.Logger;
定义记录器:
static Logger logger = Logger.getLogger(JavaLoggerTestResource.class.getName());
现在,在方法内包含日志记录:
logger.warning("Logging warning message...");
该消息将输出到应用程序服务器的 trace.log
文件中。 如果服务器管理员正在从 MobileFirst Server 向 MobileFirst Analytics Server 转发日志,那么 logger
消息还将显示在 MobileFirst Analytics Console 的基础架构 → 服务器日志搜索视图中。
访问日志文件
- 在 MobileFirst Server 的预安装中,根据底层应用程序服务器提供该文件。
- 要获取以下各项中云部署中的日志:
- IBM Containers 或 Liberty Build Pack,请参阅 IBM Containers 日志和跟踪集合教程。
- Mobile Foundation IBM Cloud 服务,请参阅使用 Mobile Foundation 教程中的访问服务器日志部分。
将日志转发到分析服务器
也可以将日志转发至分析控制台。
- 在 MobileFirst Operations Console 中,选择侧边栏导航中的设置选项。
- 单击“运行时属性”选项卡中的编辑按钮。
- 在分析 → 更多程序包部分,指定 Java 适配器的类名(例如
com.sample.JavaLoggerTestResource
),以将日志转发到 MobileFirst Server。
Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.
Last modified on June 01, 2020