From b9c9ac82975176aafb275907ce08ccbb8e233763 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Wed, 20 Nov 2024 11:53:26 +0100 Subject: [PATCH 1/3] Make timestamp prefix in logs configurable --- config/default.json | 3 ++- src/utils/logger.js | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/config/default.json b/config/default.json index ddac7ff..3c341d9 100644 --- a/config/default.json +++ b/config/default.json @@ -8,7 +8,8 @@ "host": "smtp-relay.sendinblue.com", "username": "admin@opentermsarchive.org" }, - "sendMailOnError": false + "sendMailOnError": false, + "timestampPrefix": true } } } diff --git a/src/utils/logger.js b/src/utils/logger.js index 52f244d..6db0fdd 100644 --- a/src/utils/logger.js +++ b/src/utils/logger.js @@ -12,7 +12,11 @@ const logger = winston.createLogger({ format: combine( colorize(), timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), - printf(({ level, message, timestamp }) => `${timestamp} ${level.padEnd(15)} ${message}`), + printf(({ level, message, timestamp }) => { + const timestampPrefix = config.get('@opentermsarchive/federation-api.logger.timestampPrefix') ? `${timestamp} ` : ''; + + return `${timestampPrefix}${level.padEnd(15)} ${message}`; + }), ), transports, rejectionHandlers: transports, From 9733aaf6bc4ed7d93d2f00fa636f1f959d56007f Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Wed, 20 Nov 2024 11:53:35 +0100 Subject: [PATCH 2/3] Use ISO 8601 format for timestamps prefix in logs --- src/utils/logger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/logger.js b/src/utils/logger.js index 6db0fdd..1bddd2f 100644 --- a/src/utils/logger.js +++ b/src/utils/logger.js @@ -11,7 +11,7 @@ const transports = [new winston.transports.Console({ silent: process.env.NODE_EN const logger = winston.createLogger({ format: combine( colorize(), - timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), + timestamp({ format: 'YYYY-MM-DDTHH:mm:ssZ' }), printf(({ level, message, timestamp }) => { const timestampPrefix = config.get('@opentermsarchive/federation-api.logger.timestampPrefix') ? `${timestamp} ` : ''; From cc51f8dc793f9453a3a6d9fec490ccfdf2c31899 Mon Sep 17 00:00:00 2001 From: Nicolas Dupont Date: Wed, 20 Nov 2024 11:59:40 +0100 Subject: [PATCH 3/3] Add changelog entry --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecae9e0..9ea094b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,13 @@ 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 [engine CONTRIBUTING file](https://github.com/OpenTermsArchive/engine/blob/main/CONTRIBUTING.md#changelog). This codebase adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## Unreleased +## 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/federation-api.logger.timestampPrefix` to `true` or `false` in your configuration file](https://docs.opentermsarchive.org/api/federation/#configuring) to control this feature. ## 2.0.0 - 2024-06-13