Initial commit: LogMaster with Viewer Collector Monitor modes
This commit is contained in:
101
dist-server/configFile.js
Normal file
101
dist-server/configFile.js
Normal file
@@ -0,0 +1,101 @@
|
||||
"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.getConfigFilePath = getConfigFilePath;
|
||||
exports.loadConfigFile = loadConfigFile;
|
||||
exports.saveConfigFile = saveConfigFile;
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const CONFIG_FILE = 'logviewer.config.json';
|
||||
function getConfigFilePath() {
|
||||
return path.join(process.cwd(), CONFIG_FILE);
|
||||
}
|
||||
function loadConfigFile() {
|
||||
const defaults = {
|
||||
mode: 'both',
|
||||
port: 8080,
|
||||
host: '0.0.0.0',
|
||||
viewer: {
|
||||
sources: [],
|
||||
theme: 'dark',
|
||||
refreshInterval: 2000,
|
||||
tailMode: true,
|
||||
maxLines: 50000,
|
||||
defaultLevel: 'ALL',
|
||||
},
|
||||
collector: {
|
||||
enabled: true,
|
||||
storageDir: './collector-data',
|
||||
maxLinesPerStream: 100000,
|
||||
maxStreams: 50,
|
||||
persistToDisk: true,
|
||||
udp: { enabled: true, port: 5140 },
|
||||
rotation: { maxSizeBytes: 5242880, maxAgeMs: 600000, compression: 'gzip', fileExtension: '.log' },
|
||||
forwardTargets: [],
|
||||
},
|
||||
s3: { sources: {} },
|
||||
remoteCollector: { url: '' },
|
||||
};
|
||||
const filePath = getConfigFilePath();
|
||||
if (fs.existsSync(filePath)) {
|
||||
try {
|
||||
const fileContent = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
||||
return deepMerge(defaults, fileContent);
|
||||
}
|
||||
catch (err) {
|
||||
console.error(`Error reading ${CONFIG_FILE}:`, err.message);
|
||||
}
|
||||
}
|
||||
return defaults;
|
||||
}
|
||||
function saveConfigFile(config) {
|
||||
const filePath = getConfigFilePath();
|
||||
const existing = loadConfigFile();
|
||||
const merged = deepMerge(existing, config);
|
||||
fs.writeFileSync(filePath, JSON.stringify(merged, null, 2));
|
||||
}
|
||||
function deepMerge(target, source) {
|
||||
const result = { ...target };
|
||||
for (const key of Object.keys(source)) {
|
||||
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
|
||||
result[key] = deepMerge(target[key] || {}, source[key]);
|
||||
}
|
||||
else {
|
||||
result[key] = source[key];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
//# sourceMappingURL=configFile.js.map
|
||||
Reference in New Issue
Block a user