Skip to content

Commit fa67585

Browse files
committed
improve log file naming by including seconds and enhance error handling during log file copy
1 parent bc7090b commit fa67585

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/functions/logFileUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const path = require('path');
55

66
function generateLogFileName() {
77
const date = new Date();
8-
return `webgfa-${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}-${date.getHours()}-${date.getMinutes()}.log`;
8+
return `webgfa-${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}--${date.getHours()}-${date.getMinutes()}-${date.getSeconds()}.log`;
99
}
1010
function getLogFileName(file) {
1111
if (!file) return null;

src/server.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ const logUtils = require('./functions/logFileUtils.js');
1818
/////////////////////////////////////////////////////////////
1919

2020
// Log file handling
21-
if (!fs.existsSync(path.resolve(__dirname, '../log'))) fs.mkdirSync(path.resolve(__dirname, '../log'), { recursive: true });
22-
21+
fs.mkdir(path.resolve(__dirname, '../log'), { recursive: true }).catch(() => {});
2322
try {
2423
logUtils.copyLogFile('../server.log', '../log/' + logUtils.getLogFileName('../server.log'));
2524
console.log('Copied ../server.log to ../log/' + logUtils.getLogFileName('../server.log'));
2625
} catch (error) {
27-
console.error('The copy log code is fucked:', error);
26+
console.error('Error when copying log file:', error);
2827
}
2928
console.log("--NAME-START--");
3029
console.log(logUtils.generateLogFileName());

0 commit comments

Comments
 (0)