feat: 保存 renderer 日志到文件

This commit is contained in:
qier222 2022-04-16 13:30:25 +08:00
parent d3089b8940
commit 4c625b172c
No known key found for this signature in database
GPG key ID: 9C85007ED905F14D
12 changed files with 61 additions and 31 deletions

View file

@ -2,7 +2,7 @@ import { db, Tables } from './db'
import type { FetchTracksResponse } from '../renderer/api/track'
import { app } from 'electron'
import { Request, Response } from 'express'
import logger from './logger'
import log from './log'
import fs from 'fs'
import * as musicMetadata from 'music-metadata'
import { APIs } from './CacheAPIsName'
@ -203,7 +203,7 @@ class Cache {
if (api === APIs.SongDetail) {
const cache = this.get(api, req.query)
if (cache) {
logger.debug(`[cache] Cache hit for ${req.path}`)
log.debug(`[cache] Cache hit for ${req.path}`)
return cache
}
}
@ -220,7 +220,7 @@ class Cache {
)
if (!isAudioFileExists) return
logger.debug(`[cache] Audio cache hit for ${req.path}`)
log.debug(`[cache] Audio cache hit for ${req.path}`)
return {
data: [
@ -306,9 +306,9 @@ class Cache {
await fs.writeFile(`${path}/${id}-${br}.${type}`, buffer, error => {
if (error) {
return logger.error(`[cache] cacheAudio failed: ${error}`)
return log.error(`[cache] cacheAudio failed: ${error}`)
}
logger.info(`Audio file ${id}-${br}.${type} cached!`)
log.info(`Audio file ${id}-${br}.${type} cached!`)
db.upsert(Tables.Audio, {
id,
@ -318,7 +318,7 @@ class Cache {
updateAt: Date.now(),
})
logger.info(`[cache] cacheAudio ${id}-${br}.${type}`)
log.info(`[cache] cacheAudio ${id}-${br}.${type}`)
})
}
}