fix: logger

This commit is contained in:
HuanLinOTO 2023-08-27 21:50:27 +08:00
parent 50b2a23ee0
commit 2d3f52c69e
3 changed files with 35 additions and 37 deletions

@ -2,6 +2,7 @@ const { exit } = require("process")
const fs = require("fs") const fs = require("fs")
const nodemailer = require('nodemailer') const nodemailer = require('nodemailer')
const { default: axios } = require("axios") const { default: axios } = require("axios")
const { log } = require("./logger")
exports.NotificationURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/listNotifications?status=NotificationStatusUnread&type=NotificationTypePopup&is_sort=true' exports.NotificationURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/listNotifications?status=NotificationStatusUnread&type=NotificationTypePopup&is_sort=true'
exports.WalletURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/wallet/wallet/get' exports.WalletURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/wallet/wallet/get'

@ -5,26 +5,12 @@ const reggol = require("reggol")
const { getConfigs, checkConfigs, makeHeader, Notification, Wallet, SendLog, AppVersion, getGlobalConfig } = require("./config") const { getConfigs, checkConfigs, makeHeader, Notification, Wallet, SendLog, AppVersion, getGlobalConfig } = require("./config")
const urlconfig = require("./config") const urlconfig = require("./config")
const nodemailer = require('nodemailer') const { log } = require("./logger")
(async () => {
const baseLogger = new reggol("GenshinCloudPlayHelper") log.info("开始获取全局配置")
var logContent = `` var globalConfig = getGlobalConfig();
log.info("获取成功")
const log = { if (globalConfig.sendMail == true) {
info(content){
logContent += `<strong style="color: green">[info]</strong> ${content}<br>`
baseLogger.info(content)
},
error(content){
logContent += `<strong style="color: red">[error]</strong> ${content}<br>`
baseLogger.error(content)
}
}
log.info("开始获取全局配置")
var globalConfig = getGlobalConfig();
log.info("获取成功")
if (globalConfig.sendMail == true) {
log.info("组装邮件发射器") log.info("组装邮件发射器")
var transporter = nodemailer.createTransport({ var transporter = nodemailer.createTransport({
host: globalConfig.mailConfig.smtpServer, host: globalConfig.mailConfig.smtpServer,
@ -35,14 +21,12 @@ if (globalConfig.sendMail == true) {
pass: globalConfig.mailConfig.pass pass: globalConfig.mailConfig.pass
} }
}); });
} }
var configs = getConfigs(); var configs = getConfigs();
// console.log(configs); // console.log(configs);
log.info(`正在检测配置有效性`) log.info(`正在检测配置有效性`)
checkConfigs(configs) checkConfigs(configs)
log.info("检测完毕!") log.info("检测完毕!")
(async () => {
log.info("正在获取版本号") log.info("正在获取版本号")
var appversion = await AppVersion(); var appversion = await AppVersion();
appversion = appversion.data.package_version appversion = appversion.data.package_version

13
src/logger.js Normal file

@ -0,0 +1,13 @@
const baseLogger = new reggol("GenshinCloudPlayHelper")
var logContent = ``
exports.log = {
info(content){
logContent += `<strong style="color: green">[info]</strong> ${content}<br>`
baseLogger.info(content)
},
error(content){
logContent += `<strong style="color: red">[error]</strong> ${content}<br>`
baseLogger.error(content)
}
}