From 2d3f52c69e1b173b878d371b15d65e1eff756080 Mon Sep 17 00:00:00 2001 From: HuanLinOTO Date: Sun, 27 Aug 2023 21:50:27 +0800 Subject: [PATCH] fix: logger --- src/config.js | 1 + src/index.js | 58 +++++++++++++++++++-------------------------------- src/logger.js | 13 ++++++++++++ 3 files changed, 35 insertions(+), 37 deletions(-) create mode 100644 src/logger.js diff --git a/src/config.js b/src/config.js index 2e5d839..ff578c8 100644 --- a/src/config.js +++ b/src/config.js @@ -2,6 +2,7 @@ const { exit } = require("process") const fs = require("fs") const nodemailer = require('nodemailer') 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.WalletURL = 'https://api-cloudgame.mihoyo.com/hk4e_cg_cn/wallet/wallet/get' diff --git a/src/index.js b/src/index.js index 1c6f430..0856c94 100644 --- a/src/index.js +++ b/src/index.js @@ -5,44 +5,28 @@ const reggol = require("reggol") const { getConfigs, checkConfigs, makeHeader, Notification, Wallet, SendLog, AppVersion, getGlobalConfig } = require("./config") const urlconfig = require("./config") -const nodemailer = require('nodemailer') - -const baseLogger = new reggol("GenshinCloudPlayHelper") -var logContent = `` - -const log = { - info(content){ - logContent += `[info] ${content}
` - baseLogger.info(content) - }, - error(content){ - logContent += `[error] ${content}
` - 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("检测完毕!") - +const { log } = require("./logger") (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("正在获取版本号") var appversion = await AppVersion(); appversion = appversion.data.package_version diff --git a/src/logger.js b/src/logger.js new file mode 100644 index 0000000..acc1860 --- /dev/null +++ b/src/logger.js @@ -0,0 +1,13 @@ +const baseLogger = new reggol("GenshinCloudPlayHelper") +var logContent = `` + +exports.log = { + info(content){ + logContent += `[info] ${content}
` + baseLogger.info(content) + }, + error(content){ + logContent += `[error] ${content}
` + baseLogger.error(content) + } +} \ No newline at end of file