Skip to content

Commit

Permalink
2.3.5
Browse files Browse the repository at this point in the history
* fix: Fix the issue that logger broke main process.

* fix: Change log file position, currently in data folder.
  • Loading branch information
nfnfgo authored Jul 13, 2024
1 parent 79e6110 commit 504e67f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"slug": "markdown_it",
"icon": "./icon.png",
"description": "为 QQNT 提供 Markdown 渲染",
"version": "2.3.4",
"version": "2.3.5",
"authors": [
{
"name": "d0j1a_1701",
Expand All @@ -16,7 +16,7 @@
"repo": "d0j1a1701/LiteLoaderQQNT-Markdown",
"branch": "v4",
"release": {
"tag": "2.3.4",
"tag": "2.3.5",
"file": "Release.zip"
}
},
Expand Down
17 changes: 11 additions & 6 deletions src/utils/logger_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ declare const LiteLoader: LiteLoaderInterFace<Object>;

export const LogPathHelper = {
getLogFolderPath() {
return path.join(LiteLoader.plugins.markdown_it.path.plugin, 'log');
return path.join(LiteLoader.plugins.markdown_it.path.data, 'log');
},

/**
Expand All @@ -20,30 +20,35 @@ export const LogPathHelper = {
// generate log file name if not received
logFileName ??= (new Date().toISOString()).replaceAll(':', '-');

return path.join(LiteLoader.plugins.markdown_it.path.plugin, 'log', `${logFileName}.log`);
return path.join(LogPathHelper.getLogFolderPath(), `${logFileName}.log`);
}
};

/**
* Generate a writer function that used to write log into log file.
*/
export function generateMainProcessLogerWriter() {
var logFolderPath = LogPathHelper.getLogFolderPath();
var logFilePath = LogPathHelper.getLogFilePath();
let logFolderPath = LogPathHelper.getLogFolderPath();
let logFilePath = LogPathHelper.getLogFilePath();

console.log(`[markdown-it] logFolderPath: ${logFolderPath}`);
console.log(`[markdown-it] logFilePath: ${logFilePath}`);

// clear former log file
rmSync(logFolderPath, { recursive: true });
try {
rmSync(logFolderPath, { recursive: true });
} catch (e) {
console.error('[markdown-it] Failed to remove previous log file');
}

// create dir if not exists
try {
if (!existsSync(logFolderPath)) {
mkdirSync(logFolderPath, { recursive: true });
}
} catch (err) {
console.error(err);
console.error('[markdown-it] Failed to create log directory');
return undefined;
}

var stream = createWriteStream(logFilePath, {
Expand Down

0 comments on commit 504e67f

Please sign in to comment.