mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
Merge pull request #36842 from overleaf/em-tpds-typescript
Convert third-party-datastore to TypeScript GitOrigin-RevId: 028172063d0cfe03c0f105f48ab66020c79ea50e
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user