mb-rrvideo-server 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docker-compose.yml +2 -2
- package/package.json +1 -1
- package/src/logger.js +19 -2
package/docker-compose.yml
CHANGED
package/package.json
CHANGED
package/src/logger.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
+
const config = require('./config');
|
|
4
|
+
|
|
5
|
+
const LOG_LEVELS = {
|
|
6
|
+
'DEBUG': 0,
|
|
7
|
+
'INFO': 1,
|
|
8
|
+
'WARN': 2,
|
|
9
|
+
'ERROR': 3
|
|
10
|
+
};
|
|
3
11
|
|
|
4
12
|
class Logger {
|
|
5
13
|
constructor() {
|
|
6
14
|
this.buffers = new Map(); // fileKey -> { logs: [], timer: null }
|
|
7
|
-
this.flushInterval = 2000; // 2秒
|
|
8
|
-
this.bufferMaxSize = 500; // 500条
|
|
15
|
+
this.flushInterval = config.get('log.flush_interval', 2000); // 默认2秒
|
|
16
|
+
this.bufferMaxSize = config.get('log.buffer_max_size', 500); // 默认500条
|
|
9
17
|
this.baseDir = path.join(__dirname, '../logs');
|
|
10
18
|
}
|
|
11
19
|
|
|
@@ -70,6 +78,15 @@ class Logger {
|
|
|
70
78
|
|
|
71
79
|
log(logType, fileName, message, level = 'INFO') {
|
|
72
80
|
try {
|
|
81
|
+
// 检查日志级别
|
|
82
|
+
const currentLevelStr = config.get('log.level', 'INFO').toUpperCase();
|
|
83
|
+
const currentLevel = LOG_LEVELS[currentLevelStr] !== undefined ? LOG_LEVELS[currentLevelStr] : LOG_LEVELS['INFO'];
|
|
84
|
+
const msgLevel = LOG_LEVELS[level.toUpperCase()] !== undefined ? LOG_LEVELS[level.toUpperCase()] : LOG_LEVELS['INFO'];
|
|
85
|
+
|
|
86
|
+
if (msgLevel < currentLevel) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
73
90
|
const timestamp = this.getCurrentTime();
|
|
74
91
|
const lines = String(message).split('\n');
|
|
75
92
|
const fileKey = `${logType}::${fileName}`;
|