Initial commit: LogMaster with Viewer Collector Monitor modes
This commit is contained in:
97
dist-server/configManager.js
Normal file
97
dist-server/configManager.js
Normal file
@@ -0,0 +1,97 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ConfigManager = void 0;
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
class ConfigManager {
|
||||
config;
|
||||
constructor() {
|
||||
this.config = this.loadConfig();
|
||||
}
|
||||
loadConfig() {
|
||||
this.loadEnvFile();
|
||||
const sourcesRaw = process.env.LOG_SOURCES || '';
|
||||
const sources = sourcesRaw
|
||||
.split(',')
|
||||
.map((s) => s.trim())
|
||||
.filter((s) => s.length > 0);
|
||||
return {
|
||||
sources,
|
||||
refreshInterval: parseInt(process.env.LOG_REFRESH_INTERVAL || '2000', 10),
|
||||
maxLines: parseInt(process.env.LOG_MAX_LINES || '50000', 10),
|
||||
theme: process.env.LOG_THEME || 'dark',
|
||||
defaultLevel: process.env.LOG_DEFAULT_LEVEL || 'ALL',
|
||||
tailMode: process.env.LOG_TAIL_MODE !== 'false',
|
||||
timestampRegex: process.env.LOG_TIMESTAMP_REGEX || null,
|
||||
};
|
||||
}
|
||||
loadEnvFile() {
|
||||
const envPaths = [
|
||||
path.join(process.cwd(), '.env'),
|
||||
path.join(__dirname, '..', '..', '.env'),
|
||||
];
|
||||
for (const envPath of envPaths) {
|
||||
if (fs.existsSync(envPath)) {
|
||||
const content = fs.readFileSync(envPath, 'utf-8');
|
||||
for (const line of content.split('\n')) {
|
||||
const trimmed = line.trim();
|
||||
if (trimmed && !trimmed.startsWith('#')) {
|
||||
const eqIndex = trimmed.indexOf('=');
|
||||
if (eqIndex > 0) {
|
||||
const key = trimmed.substring(0, eqIndex).trim();
|
||||
const value = trimmed.substring(eqIndex + 1).trim();
|
||||
if (!process.env[key]) {
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
getConfig() {
|
||||
return { ...this.config };
|
||||
}
|
||||
updateSources(sources) {
|
||||
this.config.sources = sources;
|
||||
}
|
||||
getSources() {
|
||||
return [...this.config.sources];
|
||||
}
|
||||
}
|
||||
exports.ConfigManager = ConfigManager;
|
||||
//# sourceMappingURL=configManager.js.map
|
||||
Reference in New Issue
Block a user