Commit 46a84a67 by trace

add log time

parent b8bb4f4a
......@@ -87,8 +87,8 @@ let allNames = names => {
return Array.from(new Set(an))
}
function log(content) {
if (isTest()) {
function log(content, useRelease = false) {
if (isTest() || useRelease) {
console.log(`[${new Date().toLocaleString()}]: ${content}`)
}
}
......@@ -108,7 +108,7 @@ try {
isFirstRun = false
} catch (err) {
isFirstRun = true
console.log(`状态文件不存在, 直接使用空的{}\n${err.toString()}`)
log(`状态文件不存在, 直接使用空的{}\n${err.toString()}`, true)
}
// 获取记录上次更新监控名得文件
......@@ -116,13 +116,13 @@ try {
let fileNames = JSON.parse(fs.readFileSync(monitorApps, 'utf-8'))
if (Array.isArray(fileNames)) {
monitorNames['vn'] = fileNames
console.log('原来只记录数组形式, 现在变更为对象形式, 原数组放到vn数组中')
log('原来只记录数组形式, 现在变更为对象形式, 原数组放到vn数组中', true)
} else {
monitorNames = fileNames
}
isFirstRun = false
} catch (err) {
console.log(`监控列表文件不存在, 直接使用空的{}\n${err.toString()}`)
log(`监控列表文件不存在, 直接使用空的{}\n${err.toString()}`, true)
}
let newOnline = [] // 新上架
let newOffline = [] // 新下架
......@@ -180,7 +180,7 @@ async function startMonitor() {
lastIntervalTime = lastIntervalTime * 2
let content = `监控出错${err}\n间隔时间调整为${(lastIntervalTime) / minute}分钟`
content += markError()
console.log(content)
log(content, true)
sendEmail(content, developer)
dingDing(content)
if (err.toString().includes('ENOSPC')) {
......@@ -410,7 +410,7 @@ async function getTop100() {
requestOptions: { timeout: requestTimeout }
})
.then(res => {
console.log(`获取到 <${monitorRegion[region]}>[${monitorType[type]}]排名: ${i * 120} ~ ${i * 120 + getNum}`)
log(`获取到 <${monitorRegion[region]}>[${monitorType[type]}]排名: ${i * 120} ~ ${i * 120 + getNum}`, true)
if (res && res.length && res.length > 0) {
res.forEach(app => {
......@@ -429,7 +429,7 @@ async function getTop100() {
}
})
.catch(err => {
console.log(`获取排名<${monitorRegion[region]}> 错误: ${err.message}`)
log(`获取排名<${monitorRegion[region]}> 错误: ${err.message}`, true)
throw err
})
}
......@@ -470,17 +470,17 @@ async function monitorIfOnline(names) {
})
.catch((err) => {
if (err.toString().includes('404')) {
console.log(`获取不到: ${name}, error: ${err}`)
log(`获取不到: ${name}, error: ${err}`, true)
failedApps.push(name)
judgeNewOffline(name)
let a = status[name] || {}
status[name] = { ...a, status: false, date: Date().toString() }
} else if (err.toString().includes('ETIMEDOUT')) {
console.log(`连接超时: ${err.toString()}`)
log(`连接超时: ${err.toString()}`, true)
throw err
} else {
errorLog.push(`Motitor Online Error: ${link(name, true)} - ${err.message}`)
console.log(`获取在线错误: ${name}, ${err.message}`)
log(`获取在线错误: ${name}, ${err.message}`, true)
}
})
}
......@@ -720,7 +720,7 @@ function aliveContent(date, lastSend) {
function sendEmail(content, to = notifyEmail) {
if (content == null || content == undefined || content == '') {
console.log('没有生成内容, 检查心跳')
log('没有生成内容, 检查心跳', true)
let date = new Date()
let lastDing = new Date(status.lastDingDate || 'Tue Jan 29 2019 19:32:24 GMT+0800 (CST)')
let lastSend = new Date(status.lastSendDate || 'Tue Jan 29 2019 19:32:24 GMT+0800 (CST)')
......@@ -744,7 +744,7 @@ function sendEmail(content, to = notifyEmail) {
}
return
}
console.log(`发送email: ${content.length}`)
log(`发送email: ${content.length}`, true)
// if (content.indexOf('Error') != -1) {
// to = developer
// } else {
......@@ -776,9 +776,9 @@ function sendEmail(content, to = notifyEmail) {
trans.sendMail(mailOption, (error, info) => {
if (error) {
return console.log(`发生错误: ${error}`);
return log(`发生错误: ${error}`, true);
}
console.log(`message ${info.messageId} send: ${info.response}`)
log(`message ${info.messageId} send: ${info.response}`, true)
})
dingDing(content, notifyDingding)
......
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 to comment