Skip to content

Commit

Permalink
尝试模板输出日志
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTzh committed Sep 28, 2020
1 parent e3bd91b commit c272365
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Role_Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ module.exports = ({
creep.moveTo(source);
} else if (actionResult === ERR_NOT_ENOUGH_RESOURCES) {
creep.room.memory.moveResource = null;
} else if (actionResult != OK) {
} else if (actionResult !== OK) {
logger.debug(`\n当前运输物品:${creep.room.memory.moveResource}\n当前Creep携带量:${creep.store.getUsedCapacity(creep.room.memory.moveResource)}\n当前总空间:${creep.store.getCapacity(creep.room.memory.moveResource)}`)
logger.info(`${creep}拿取结果出错:${actionResult}`);
logger.creepLog(creep, "拿取资源", actionResult);
}
} else {
logger.debug(`[${creep.name}]没有被指派工作目标!`);
Expand All @@ -58,7 +58,7 @@ module.exports = ({
} else if (actionResult === ERR_FULL) {
//当工厂存储满后,直接重新筛选要搬运的资源
creep.room.memory.moveResource = null;
} else if (actionResult != OK) {
} else if (actionResult !== OK) {
logger.info(`[${creep}]存储结果出错:${actionResult}`);
logger.info(`[${creep.name}]当前被指派搬运物品:${creep.room.memory.moveResource}`);
}
Expand Down
15 changes: 10 additions & 5 deletions utils.log.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Logger {

_canLog(levelNum) {
if (levelNum == null) return false;
return this.forceControl == true || levelNum >= this.logSettingNum && this.forceControl == null
return this.forceControl === true || levelNum >= this.logSettingNum && this.forceControl == null;
}

_log(level, messages) {
Expand All @@ -55,19 +55,24 @@ class Logger {
}

debug(...message) {
this._log("DEBUG", message)
this._log("DEBUG", message);
}

info(...message) {
this._log("INFO ", message)
this._log("INFO ", message);
}

warn(...message) {
this._log("WARN ", message)
this._log("WARN ", message);
}

error(...message) {
this._log("ERROR", message)
this._log("ERROR", message);
}

creepLog(creep, action, code) {
const message = `${creep}${creep.room}执行任务[${action}]时出错,错误代码:[${code}]`;
this._log("INFO ", message);
}
}

Expand Down

0 comments on commit c272365

Please sign in to comment.