-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.js
More file actions
36 lines (29 loc) · 965 Bytes
/
Copy pathlogger.js
File metadata and controls
36 lines (29 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Handles all logging functionality
import * as fs from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Create logs directory if it doesn't exist
const logsDir = path.join(__dirname, 'logs');
if (!fs.existsSync(logsDir)) {
fs.mkdirSync(logsDir);
}
export function logToFile(message, type = 'info') {
const now = new Date();
const timestamp = now.toISOString();
const date = now.toISOString().split('T')[0];
const logFiles = {
trade: `trades_${date}.log`,
error: `errors_${date}.log`,
info: `info_${date}.log`
};
const fileName = logFiles[type] || logFiles.info;
const logPath = path.join(logsDir, fileName);
const logEntry = `[${timestamp}] ${message}\n`;
try {
fs.appendFileSync(logPath, logEntry);
} catch (error) {
console.error(`Error writing to log file: ${error.message}`);
}
}