Kapsel的Logger Plugin能够使Mobile Apps能够方便记录日志。仍然在之前的LogonExercise
Project中进行添加Logger Plugin。步骤如下:
1. 安装所需插件
cd c:\Kapsel_Projects\LogonExercise
–安装Cordova自己的Console Plugin:
cordova plugin add <img src="/oldimg/50/https://www.ut163.com/wp-content/uploads/2019/08/20190826033701-93.jpg" alt="SMP3.0学习笔记之九使用KapselLogger插件记录日志” />
3.
修改文件main.html文件:
a.在logonSuccessCallback方法中增加记录日志到Console并设置Kapsel的日志Level:
function logonSuccessCallback(result) {
console.log(“Logon was
successful!”);
sap.Logger.setLogLevel(sap.Logger.INFO, function(logLevel)
{console.log(“Log level
set”);
}, function() {
console.log(“Failed to set log level”);
});
// If result is not null, we have successful login
if (result) {
// Set the application Context
// This has all the good stuff in it
applicationContext = result;
// Read the Airlines from Gateway and display
readAirlines(applicationContext);
}
}
b.增加logMessageInfoToSMP方法:
function logMessageInfoToSMP(message) {
//TODO: Log info message with Kapsel Logger
sap.Logger.error(message);
//TODO: Upload the log to the server
sap.Logger.upload(function() {
console.log(“Logs uploaded to server successfully”);
}, function(e) {
console.log(“Upload Failed. Status: ” e.statusCode “, Message:
“
e.statusMessage);
});
}
c. 在readAirlines方法中添加如下代码以便记录日志:
logMessageInfoToSMP(“User ” user ” is calling Read Airlines
service!”);
4. 准备重新部署LogonExercise:
cd c:\Kapsel_Projects\LogonExercise
cordova -d prepare android
5. 在Eclipse中运行该project,Logon成功后会看到有日志打出:
<img src="/oldimg/50/https://www.ut163.com/wp-content/uploads/2019/08/20190826033701-85.jpg" alt="SMP3.0学习笔记之九使用KapselLogger插件记录日志” />
6. 同时还可以在SMP3.0的管理界面中打开移动终端的Kapsel的日志进行查看:
<img src="/oldimg/50/https://www.ut163.com/wp-content/uploads/2019/08/20190826033701-92.jpg" alt="SMP3.0学习笔记之九使用KapselLogger插件记录日志” />