Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make timestamp prefix in logs configurable #7

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"host": "smtp-relay.sendinblue.com",
"username": "admin@opentermsarchive.org"
},
"sendMailOnError": false
"sendMailOnError": false,
"timestampPrefix": true
}
}
}
8 changes: 6 additions & 2 deletions src/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ 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' }),
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/federation-api.logger.timestampPrefix') ? `${timestamp} ` : '';

return `${timestampPrefix}${level.padEnd(15)} ${message}`;
}),
),
transports,
rejectionHandlers: transports,
Expand Down
Loading