@orpc/experimental-pino 0.0.1 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +7 -7
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ declare const CONTEXT_LOGGER_SYMBOL: unique symbol;
|
|
|
6
6
|
interface LoggerContext {
|
|
7
7
|
[CONTEXT_LOGGER_SYMBOL]?: Logger;
|
|
8
8
|
}
|
|
9
|
-
declare function getLogger(context:
|
|
9
|
+
declare function getLogger(context: LoggerContext): Logger | undefined;
|
|
10
10
|
|
|
11
11
|
interface LoggingHandlerPluginOptions<T extends Context> {
|
|
12
12
|
/**
|
|
@@ -29,7 +29,7 @@ interface LoggingHandlerPluginOptions<T extends Context> {
|
|
|
29
29
|
* - request handled
|
|
30
30
|
* - no matching procedure found
|
|
31
31
|
*
|
|
32
|
-
* @default
|
|
32
|
+
* @default false
|
|
33
33
|
*/
|
|
34
34
|
logRequestResponse?: boolean;
|
|
35
35
|
/**
|
|
@@ -40,7 +40,7 @@ interface LoggingHandlerPluginOptions<T extends Context> {
|
|
|
40
40
|
*
|
|
41
41
|
* @remarks If a signal is used for multiple requests, this may lead to un-efficient memory usage (listeners never removed).
|
|
42
42
|
*
|
|
43
|
-
* @default
|
|
43
|
+
* @default false
|
|
44
44
|
*/
|
|
45
45
|
logRequestAbort?: boolean;
|
|
46
46
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ declare const CONTEXT_LOGGER_SYMBOL: unique symbol;
|
|
|
6
6
|
interface LoggerContext {
|
|
7
7
|
[CONTEXT_LOGGER_SYMBOL]?: Logger;
|
|
8
8
|
}
|
|
9
|
-
declare function getLogger(context:
|
|
9
|
+
declare function getLogger(context: LoggerContext): Logger | undefined;
|
|
10
10
|
|
|
11
11
|
interface LoggingHandlerPluginOptions<T extends Context> {
|
|
12
12
|
/**
|
|
@@ -29,7 +29,7 @@ interface LoggingHandlerPluginOptions<T extends Context> {
|
|
|
29
29
|
* - request handled
|
|
30
30
|
* - no matching procedure found
|
|
31
31
|
*
|
|
32
|
-
* @default
|
|
32
|
+
* @default false
|
|
33
33
|
*/
|
|
34
34
|
logRequestResponse?: boolean;
|
|
35
35
|
/**
|
|
@@ -40,7 +40,7 @@ interface LoggingHandlerPluginOptions<T extends Context> {
|
|
|
40
40
|
*
|
|
41
41
|
* @remarks If a signal is used for multiple requests, this may lead to un-efficient memory usage (listeners never removed).
|
|
42
42
|
*
|
|
43
|
-
* @default
|
|
43
|
+
* @default false
|
|
44
44
|
*/
|
|
45
45
|
logRequestAbort?: boolean;
|
|
46
46
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { get, isAsyncIteratorObject, overlayProxy } from '@orpc/shared';
|
|
2
1
|
import { mapEventIterator } from '@orpc/client';
|
|
2
|
+
import { ORPC_NAME, isAsyncIteratorObject, overlayProxy } from '@orpc/shared';
|
|
3
3
|
import pino from 'pino';
|
|
4
4
|
|
|
5
5
|
const CONTEXT_LOGGER_SYMBOL = Symbol("ORPC_PINO_CONTEXT_LOGGER_SYMBOL");
|
|
6
6
|
function getLogger(context) {
|
|
7
|
-
return
|
|
7
|
+
return context[CONTEXT_LOGGER_SYMBOL];
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
class LoggingHandlerPlugin {
|
|
@@ -15,8 +15,8 @@ class LoggingHandlerPlugin {
|
|
|
15
15
|
constructor(options = {}) {
|
|
16
16
|
this.logger = options.logger ?? pino();
|
|
17
17
|
this.generateId = options.generateId ?? (() => crypto.randomUUID());
|
|
18
|
-
this.logRequestResponse = options.logRequestResponse;
|
|
19
|
-
this.logRequestAbort = options.logRequestAbort;
|
|
18
|
+
this.logRequestResponse = options.logRequestResponse ?? false;
|
|
19
|
+
this.logRequestAbort = options.logRequestAbort ?? false;
|
|
20
20
|
}
|
|
21
21
|
init(options) {
|
|
22
22
|
options.rootInterceptors ??= [];
|
|
@@ -24,7 +24,7 @@ class LoggingHandlerPlugin {
|
|
|
24
24
|
options.clientInterceptors ??= [];
|
|
25
25
|
options.rootInterceptors.unshift(async (interceptorOptions) => {
|
|
26
26
|
const logger = (interceptorOptions.context[CONTEXT_LOGGER_SYMBOL] ?? this.logger).child({
|
|
27
|
-
|
|
27
|
+
rpc: { id: this.generateId(interceptorOptions), system: ORPC_NAME }
|
|
28
28
|
});
|
|
29
29
|
if (!logger.bindings().req) {
|
|
30
30
|
logger.setBindings({
|
|
@@ -74,7 +74,7 @@ class LoggingHandlerPlugin {
|
|
|
74
74
|
}
|
|
75
75
|
return result;
|
|
76
76
|
} catch (error) {
|
|
77
|
-
|
|
77
|
+
logger.error(error);
|
|
78
78
|
throw error;
|
|
79
79
|
}
|
|
80
80
|
});
|
|
@@ -93,7 +93,7 @@ class LoggingHandlerPlugin {
|
|
|
93
93
|
});
|
|
94
94
|
options.clientInterceptors.unshift(async ({ next, path, context, signal }) => {
|
|
95
95
|
const logger = getLogger(context);
|
|
96
|
-
logger?.setBindings({
|
|
96
|
+
logger?.setBindings({ rpc: { ...logger.bindings().rpc, method: path.join(".") } });
|
|
97
97
|
const output = await next();
|
|
98
98
|
if (isAsyncIteratorObject(output)) {
|
|
99
99
|
return overlayProxy(output, mapEventIterator(
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/experimental-pino",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.11.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"pino": ">=10.1.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@orpc/
|
|
31
|
-
"@orpc/
|
|
32
|
-
"@orpc/
|
|
30
|
+
"@orpc/client": "1.11.1",
|
|
31
|
+
"@orpc/server": "1.11.1",
|
|
32
|
+
"@orpc/shared": "1.11.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"pino": "^10.1.0"
|