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,44 +5,28 @@ 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")
const baseLogger = new reggol("GenshinCloudPlayHelper")
var logContent = ``
const 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)
}
}
log.info("开始获取全局配置")
var globalConfig = getGlobalConfig();
log.info("获取成功")
if (globalConfig.sendMail == true) {
log.info("组装邮件发射器")
var transporter = nodemailer.createTransport({
host: globalConfig.mailConfig.smtpServer,
port: globalConfig.mailConfig.smtpPort,
secure: globalConfig.mailConfig.smtpSecure,
auth: {
user: globalConfig.mailConfig.user,
pass: globalConfig.mailConfig.pass
}
});
}
var configs = getConfigs();
// console.log(configs);
log.info(`正在检测配置有效性`)
checkConfigs(configs)
log.info("检测完毕!")
(async () => { (async () => {
log.info("开始获取全局配置")
var globalConfig = getGlobalConfig();
log.info("获取成功")
if (globalConfig.sendMail == true) {
log.info("组装邮件发射器")
var transporter = nodemailer.createTransport({
host: globalConfig.mailConfig.smtpServer,
port: globalConfig.mailConfig.smtpPort,
secure: globalConfig.mailConfig.smtpSecure,
auth: {
user: globalConfig.mailConfig.user,
pass: globalConfig.mailConfig.pass
}
});
}
var configs = getConfigs();
// console.log(configs);
log.info(`正在检测配置有效性`)
checkConfigs(configs)
log.info("检测完毕!")
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)
}
}