Commit 568f96b1 by pye52

增加指令执行过程中的日志输出

parent f9ec85fc
......@@ -69,6 +69,7 @@ public class LogCommandHandler extends CommandHandler {
} catch (ParseException e) {
LogUtils.w(TAG, "日志上传,结束时间解析失败: " + data.toString(), e);
}
LogUtils.d(TAG, "筛选从" + startTime.toString() + "到" + endTime.toString() + "的日志文件");
}
// 检查传入的指定日期是否合法
......@@ -114,6 +115,7 @@ public class LogCommandHandler extends CommandHandler {
} else {
logDir = new File(LogUtils.getConfig().getDir());
}
LogUtils.d(TAG, "待上传日志文件类型: " + logType);
return logDir;
}
......@@ -124,6 +126,7 @@ public class LogCommandHandler extends CommandHandler {
FileUtils.delete(dir);
}
boolean result = dir.mkdirs();
LogUtils.d(TAG, "临时目录创建" + (result ? "成功" : "失败"));
if (result) {
return dir;
} else {
......@@ -139,11 +142,16 @@ public class LogCommandHandler extends CommandHandler {
List<File> logFiles = FileUtils.listFilesInDirWithFilter(src, filter, false, null);
boolean copyResult = true;
wait("筛选目标日志文件", 10);
int count = 0;
File descFile;
boolean tempCopyResult;
for (File file : logFiles) {
descFile = new File(descDir, file.getName());
copyResult = copyResult && FileUtils.copy(file, descFile);
tempCopyResult = FileUtils.copy(file, descFile);
copyResult = copyResult && tempCopyResult;
if (tempCopyResult) count++;
}
LogUtils.d(TAG, "待上传日志文件总数: " + logFiles.size() + ", 复制成功文件总数: " + count);
return !logFiles.isEmpty() && copyResult;
}
......@@ -156,6 +164,7 @@ public class LogCommandHandler extends CommandHandler {
"_" + format.format(endTime) +
"_" + deviceSN + ".zip";
fileNameForServer = fileNameForServer.replace(" ", "_");
LogUtils.d(TAG, "开始上传日志: " + fileNameForServer);
RequestBody requestBody = RequestBody.create(zip, MediaType.parse("application/x-zip-compressed"));
MultipartBody.Part body = MultipartBody.Part.createFormData("file", fileNameForServer, requestBody);
try {
......
......@@ -6,8 +6,11 @@ import com.bgycc.smartcanteen.entity.Command;
import com.bgycc.smartcanteen.entity.CommandResponse;
import com.bgycc.smartcanteen.entity.CommandWifiConfig;
import com.bgycc.smartcanteen.utils.NetworkUtils;
import com.blankj.utilcode.util.LogUtils;
import com.google.gson.Gson;
import static com.bgycc.smartcanteen.utils.SmartCanteenUtils.TAG;
public class WifiConfigCommandHandler extends CommandHandler {
private static final long DEFAULT_DELAY = 3000;
private static final long POLLING_DELAY = 100;
......@@ -28,6 +31,7 @@ public class WifiConfigCommandHandler extends CommandHandler {
if (!NetworkUtils.setEnable(true)) {
String failedMessage = "无法启动Wifi";
wait(failedMessage, 5);
LogUtils.e(TAG, failedMessage);
Thread.sleep(DEFAULT_DELAY);
return failedResult(failedMessage);
}
......@@ -39,6 +43,7 @@ public class WifiConfigCommandHandler extends CommandHandler {
String type = data.getType();
wait("正在配置Wifi", 10);
LogUtils.d(TAG, "开始配置wifi, ssid: " + ssid + ", identity: " + identity + ", pwd: " + pwd + ", type: " + type);
try {
NetworkUtils.connect(ssid, identity, pwd, type);
// 轮训检查wifi是否链接成功
......@@ -50,10 +55,12 @@ public class WifiConfigCommandHandler extends CommandHandler {
}
String message = "Wifi配置成功";
wait(message, 50);
LogUtils.d(TAG, message);
Thread.sleep(DEFAULT_DELAY);
return successResult(message);
}
} catch (Exception e) {
LogUtils.e(TAG, "链接wifi过程出错: " + e.getMessage(), e);
Thread.sleep(DEFAULT_DELAY);
return failedResult(e.getMessage());
}
......
......@@ -125,6 +125,7 @@ public class CommandViewModel extends ViewModel implements CommandProgressCallba
@Override
public void run() {
CommandHandler handler = null;
LogUtils.d(TAG, "开始执行指令: " + command.toString());
try {
switch (command.getAction()) {
case Command.LOG_UPLOAD:
......@@ -155,6 +156,7 @@ public class CommandViewModel extends ViewModel implements CommandProgressCallba
commandState.postValue(new CommandState(CommandState.WAIT));
CommandResponse response = handler.run();
if (response == null) {
LogUtils.d(TAG, "指令无返回结果");
return;
}
if (response.success()) {
......@@ -177,6 +179,7 @@ public class CommandViewModel extends ViewModel implements CommandProgressCallba
LogUtils.w(TAG, e.getMessage(), e);
} finally {
command.finish();
LogUtils.d(TAG, "指令执行完毕: " + command.toString());
commandRepository.updateCommand(command);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment