日志优化

This commit is contained in:
xx572959496 2024-12-05 16:48:13 +08:00
parent 1c7e4dfa54
commit 1ea24acf24

View File

@ -33,7 +33,7 @@ public class CheckLogin {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
log.info("==== 开始运行打卡任务 ===="); log.info("开始运行打卡任务");
String morning = DateUtil.today() + " 09:00:00"; String morning = DateUtil.today() + " 09:00:00";
String afternoon = DateUtil.today() + " 18:00:00"; String afternoon = DateUtil.today() + " 18:00:00";
DateTime morningDate = DateUtil.parse(morning); DateTime morningDate = DateUtil.parse(morning);
@ -41,15 +41,15 @@ public class CheckLogin {
DateTime now = DateUtil.date(); DateTime now = DateUtil.date();
DateTime beginOfDay = DateUtil.beginOfDay(now); DateTime beginOfDay = DateUtil.beginOfDay(now);
DateTime endOfDay = DateUtil.endOfDay(now); DateTime endOfDay = DateUtil.endOfDay(now);
log.info("==== 当前时间:{} ====", now.toString()); log.info("当前时间:{}", now.toString());
boolean isMorning = DateUtil.isIn(now, beginOfDay, morningDate); boolean isMorning = DateUtil.isIn(now, beginOfDay, morningDate);
boolean isAfterNoon = DateUtil.isIn(now, afternoonDate, endOfDay); boolean isAfterNoon = DateUtil.isIn(now, afternoonDate, endOfDay);
if (!isMorning && !isAfterNoon) { if (!isMorning && !isAfterNoon) {
log.info("==== 现在不是打卡时间哦! ===="); log.info("现在不是打卡时间哦!");
return; return;
} }
int singMark = isMorning ? 0 : 1; int singMark = isMorning ? 0 : 1;
log.info("==== 现在要打 {} 卡 ====", isMorning ? "上班" : "下班"); log.info("现在要打 {} 卡", isMorning ? "上班" : "下班");
String filePath = args.length > 0 ? args[0] : DEFAULT_FILE_PATH; String filePath = args.length > 0 ? args[0] : DEFAULT_FILE_PATH;
if (!FileUtil.exist(filePath)) { if (!FileUtil.exist(filePath)) {
log.error("未自定义账号文件路径(运行命令行添加自定义账号文件路径 例如java -jar xxx.jar /use/local/user.csv默认文件路径 {} 读取为空", DEFAULT_FILE_PATH); log.error("未自定义账号文件路径(运行命令行添加自定义账号文件路径 例如java -jar xxx.jar /use/local/user.csv默认文件路径 {} 读取为空", DEFAULT_FILE_PATH);
@ -63,9 +63,9 @@ public class CheckLogin {
userList.forEach(forEachWithIndex((user, index) -> { userList.forEach(forEachWithIndex((user, index) -> {
boolean isSignSuccess = sign(user, singMark); boolean isSignSuccess = sign(user, singMark);
if (isSignSuccess) { if (isSignSuccess) {
log.info("==== {} 账号打卡成功 ====", user.getUsername()); log.info("{} 账号打卡成功", user.getUsername());
} else { } else {
log.error("==== {} 账号打卡失败 ====", user.getUsername()); log.error("{} 账号打卡失败", user.getUsername());
} }
if (index + 1 == size) { if (index + 1 == size) {
return; return;
@ -73,13 +73,13 @@ public class CheckLogin {
// 随机 1-5分钟之后执行下一个人的打卡 // 随机 1-5分钟之后执行下一个人的打卡
// 1 * 60 * 1000 // 1 * 60 * 1000
BigDecimal randomMinute = NumberUtil.round(RandomUtil.randomFloat(1, 6),2); BigDecimal randomMinute = NumberUtil.round(RandomUtil.randomFloat(1, 6),2);
log.info("==== {}分钟后 执行下个人的打卡任务 ====", randomMinute); log.info("{}分钟后 执行下个人的打卡任务", randomMinute);
ThreadUtil.safeSleep(NumberUtil.mul(randomMinute, 60, 1000)); ThreadUtil.safeSleep(NumberUtil.mul(randomMinute, 60, 1000));
})); }));
} catch (Exception e) { } catch (Exception e) {
log.error(e); log.error(e);
} finally { } finally {
log.info("==== 打卡任务结束 ===="); log.info("打卡任务结束");
} }
} }