diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bb6c99d9..66c398c0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All changes that impact users of this module are documented in this file, in the [Common Changelog](https://common-changelog.org) format with some additional specifications defined in the CONTRIBUTING file. This codebase adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased [minor] + +> Development of this release was supported by the [French Ministry for Foreign Affairs](https://www.diplomatie.gouv.fr/fr/politique-etrangere-de-la-france/diplomatie-numerique/) through its ministerial [State Startups incubator](https://beta.gouv.fr/startups/open-terms-archive.html) under the aegis of the Ambassador for Digital Affairs. + +### Added + +- Add configuration option to toggle timestamp prefix in logs; set [`@opentermsarchive/engine.logger.timestampPrefix` to `true` or `false` in your configuration file](https://docs.opentermsarchive.org/#configuring) to control this feature. + ## 2.6.0 - 2024-11-19 _Full changeset and discussions: [#1116](https://github.com/OpenTermsArchive/engine/pull/1116)._ diff --git a/config/default.json b/config/default.json index 0d3d82eac..2d18aeac3 100644 --- a/config/default.json +++ b/config/default.json @@ -48,7 +48,8 @@ "host": "smtp-relay.sendinblue.com", "username": "admin@opentermsarchive.org" }, - "sendMailOnError": false + "sendMailOnError": false, + "timestampPrefix": true }, "notifier": { "sendInBlue": { diff --git a/scripts/dataset/logger/index.js b/scripts/dataset/logger/index.js index 3bf065e94..4c2389ecf 100644 --- a/scripts/dataset/logger/index.js +++ b/scripts/dataset/logger/index.js @@ -1,3 +1,4 @@ +import config from 'config'; import winston from 'winston'; import logger from '../../../src/logger/index.js'; @@ -6,11 +7,13 @@ const { combine, timestamp, printf, colorize } = winston.format; logger.format = combine( colorize(), - timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), + timestamp({ format: 'YYYY-MM-DDTHH:MM:SSZ' }), printf(({ level, message, counter, hash, timestamp }) => { const prefix = counter && hash ? `${counter.toString().padEnd(6)} ${hash.padEnd(40)}` : ''; - return `${timestamp} ${level.padEnd(15)} ${prefix.padEnd(50)} ${message}`; + const timestampPrefix = config.get('@opentermsarchive/engine.logger.timestampPrefix') ? `${timestamp} ` : ''; + + return `${timestampPrefix}${level.padEnd(15)} ${prefix.padEnd(50)} ${message}`; }), ); diff --git a/src/collection-api/logger.js b/src/collection-api/logger.js index c1df1c8fa..c1287dbd4 100644 --- a/src/collection-api/logger.js +++ b/src/collection-api/logger.js @@ -30,8 +30,12 @@ if (config.get('@opentermsarchive/engine.logger.sendMailOnError')) { const logger = winston.createLogger({ format: combine( colorize(), - timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), - printf(({ level, message, timestamp }) => `${timestamp} ${level.padEnd(15)} ${message}`), + timestamp({ format: 'YYYY-MM-DDTHH:MM:SSZ' }), + printf(({ level, message, timestamp }) => { + const timestampPrefix = config.get('@opentermsarchive/engine.logger.timestampPrefix') ? `${timestamp} ` : ''; + + return `${timestampPrefix}${level.padEnd(15)} ${message}`; + }), ), transports, rejectionHandlers: transports, diff --git a/src/logger/index.js b/src/logger/index.js index ca8594759..ea94f489c 100644 --- a/src/logger/index.js +++ b/src/logger/index.js @@ -8,23 +8,17 @@ const { combine, timestamp, printf, colorize } = winston.format; const alignedWithColorsAndTime = combine( colorize(), - timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), + timestamp({ format: 'YYYY-MM-DDTHH:MM:SSZ' }), printf(({ level, message, timestamp, serviceId, termsType, documentId }) => { - let prefix = ''; + const servicePrefix = serviceId && termsType + ? `${serviceId} — ${termsType}${documentId ? `:${documentId}` : ''}` + : ''; - if (serviceId && termsType) { - prefix = `${serviceId} — ${termsType}`; - } - - if (documentId) { - prefix = `${prefix}:${documentId}`; - } + const truncatedPrefix = servicePrefix.length > 75 ? `${servicePrefix.slice(0, 74)}…` : servicePrefix; - if (prefix.length > 75) { - prefix = `${prefix.substring(0, 74)}…`; - } + const timestampPrefix = config.get('@opentermsarchive/engine.logger.timestampPrefix') ? `${timestamp} ` : ''; - return `${timestamp} ${level.padEnd(15)} ${prefix.padEnd(75)} ${message}`; + return `${timestampPrefix}${level.padEnd(15)} ${truncatedPrefix.padEnd(75)} ${message}`; }), );