SYNC: strict delimit logs by date

This commit is contained in:
SPRINX0\prochazka
2025-08-04 12:52:15 +02:00
committed by Diflow
parent 781cbb4668
commit ac0aebd751
5 changed files with 22 additions and 9 deletions

View File

@@ -56,7 +56,7 @@
"ncp": "^2.0.0",
"node-cron": "^2.0.3",
"on-finished": "^2.4.1",
"pinomin": "^1.0.4",
"pinomin": "^1.0.5",
"portfinder": "^1.0.28",
"rimraf": "^3.0.0",
"semver": "^7.6.3",

View File

@@ -40,6 +40,8 @@ function configureLogger() {
const consoleLogLevel = process.env.CONSOLE_LOG_LEVEL || process.env.LOG_LEVEL || 'info';
const fileLogLevel = process.env.FILE_LOG_LEVEL || process.env.LOG_LEVEL || 'debug';
const streamsByDatePart = {};
const logConfig = {
base: { pid: process.pid },
targets: [
@@ -49,10 +51,21 @@ function configureLogger() {
level: consoleLogLevel,
},
{
type: 'stream',
type: 'objstream',
// @ts-ignore
level: fileLogLevel,
stream: fs.createWriteStream(logsFilePath, { flags: 'a' }),
objstream: {
send(msg) {
const datePart = moment(msg.time).format('YYYY-MM-DD');
if (!streamsByDatePart[datePart]) {
streamsByDatePart[datePart] = fs.createWriteStream(
path.join(logsdir(), `${moment().format('YYYY-MM-DD-HH-mm')}-${process.pid}.ndjson`),
{ flags: 'a' }
);
}
streamsByDatePart[datePart].write(`${JSON.stringify(msg)}\n`);
},
},
},
],
};

View File

@@ -41,6 +41,6 @@
"dbgate-plugin-oracle": "^6.0.0-alpha.1",
"dbgate-web": "^6.0.0-alpha.1",
"dotenv": "^16.0.0",
"pinomin": "^1.0.4"
"pinomin": "^1.0.5"
}
}

View File

@@ -37,7 +37,7 @@
"debug": "^4.3.4",
"json-stable-stringify": "^1.0.1",
"lodash": "^4.17.21",
"pinomin": "^1.0.4",
"pinomin": "^1.0.5",
"toposort": "^2.0.2",
"uuid": "^3.4.0"
}

View File

@@ -11649,10 +11649,10 @@ pino-pretty@^9.1.1:
sonic-boom "^3.0.0"
strip-json-comments "^3.1.1"
pinomin@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/pinomin/-/pinomin-1.0.4.tgz#fcbc5e50745f1769a6b4d9a5a49475927e3ce556"
integrity sha512-UJFXLxbgP9t9PDIWiKeVp3/+kudjeq/7IqWUFXqmNFD7810bh3+/3H8jvf+CCvEDkKVY8ckbCNIDWHWymurqHw==
pinomin@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/pinomin/-/pinomin-1.0.5.tgz#588e3f4d39579bb6109cd8a1fadb56ff1f78a781"
integrity sha512-jWMMM/B7QLWlA9zxaIyBiY57tf4LThBIWkfav3kNIuJOIFC4WFKfnVYU0pL7xU+YHqhHYHpHsTzkNPBZAIXlpw==
pirates@^4.0.4:
version "4.0.6"