Merge pull request #36842 from overleaf/em-tpds-typescript

Convert third-party-datastore to TypeScript

GitOrigin-RevId: 028172063d0cfe03c0f105f48ab66020c79ea50e
This commit is contained in:
Eric Mc Sween
2026-09-17 12:06:14 +00:00
committed by Copybot
parent a9ad734cf4
commit 2024f85941
7 changed files with 159 additions and 2 deletions
+27
View File
@@ -16,6 +16,14 @@ const {
const EXIT_DELAY = 500
const LoggingManager = {
/**
* The serializers registered by addSerializer, kept here rather than only on
* the logger so that they survive a later initialize() call. A module that
* registers one as it is imported would otherwise lose it, since a service
* initializes its logger after its imports have run.
*/
customSerializers: {},
/**
* @param {string} name - The name of the logger
*/
@@ -34,6 +42,7 @@ const LoggingManager = {
error: Serializers.err,
req: Serializers.req,
res: Serializers.res,
...this.customSerializers,
},
streams: options.streams ?? [this._getOutputStreamConfig()],
})
@@ -44,6 +53,24 @@ const LoggingManager = {
return this
},
/**
* Register a serializer, which decides what gets recorded for a named log
* field, e.g. `logger.error({ dropboxResponseError: err }, '...')`. Callers
* add their own on top of the ones initialize() sets up, and keep them across
* a later initialize(), so registering one as a module is imported works.
*
* A serializer takes whatever was logged under that field, so it receives an
* unknown and narrows it itself, and returns the value to record in its
* place, which is only ever JSON encoded.
*
* @param {string} name - the log field the serializer applies to
* @param {(value: unknown) => unknown} serializer
*/
addSerializer(name, serializer) {
this.customSerializers[name] = serializer
this.logger.serializers[name] = serializer
},
/**
* @param {Record<string, any>|string} attributes - Attributes to log (nice serialization for err, req, res)
* @param {string} [message] - Optional message