@owox/internal-helpers 0.11.0-next-20251025220131 → 0.11.0-next-20251027113952

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.
@@ -1,9 +1,10 @@
1
+ import type { LoggerConfig, LoggerProvider } from '../types.js';
1
2
  import { LogLevel } from '../types.js';
2
- import type { LoggerProvider, LoggerConfig } from '../types.js';
3
3
  /**
4
4
  * Pino logger provider implementation
5
5
  */
6
6
  export declare class PinoLoggerProvider implements LoggerProvider {
7
+ private static sharedPrettyTransport;
7
8
  private readonly pinoLogger;
8
9
  constructor(config: LoggerConfig);
9
10
  shutdown(): Promise<void>;
@@ -12,5 +13,7 @@ export declare class PinoLoggerProvider implements LoggerProvider {
12
13
  * Build Pino options object from resolved configuration
13
14
  */
14
15
  private buildPinoOptions;
16
+ private static resolveDestination;
17
+ private static getSharedPrettyTransport;
15
18
  }
16
19
  //# sourceMappingURL=pino-logger-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pino-logger-provider.d.ts","sourceRoot":"","sources":["../../../src/logging/providers/pino-logger-provider.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,QAAQ,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhE;;GAEG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IACvD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;gBAE5B,MAAM,EAAE,YAAY;IAIhC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzB,GAAG,CACD,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,SAAS,CAAC,EAAE,KAAK,GAAG,OAAO,GAC1B,IAAI;IAsBP;;OAEG;IACH,OAAO,CAAC,gBAAgB;CA+BzB"}
1
+ {"version":3,"file":"pino-logger-provider.d.ts","sourceRoot":"","sources":["../../../src/logging/providers/pino-logger-provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAa,QAAQ,EAAE,MAAM,aAAa,CAAC;AAElD;;GAEG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IACvD,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAAkC;IACtE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;gBAE5B,MAAM,EAAE,YAAY;IAMhC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAIzB,GAAG,CACD,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,SAAS,CAAC,EAAE,KAAK,GAAG,OAAO,GAC1B,IAAI;IAsBP;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAmBxB,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAOjC,OAAO,CAAC,MAAM,CAAC,wBAAwB;CAgBxC"}
@@ -1,13 +1,16 @@
1
- import pino from 'pino';
2
1
  import { createGcpLoggingPinoConfig } from '@google-cloud/pino-logging-gcp-config';
2
+ import pino from 'pino';
3
3
  import { LogFormat, LogLevel } from '../types.js';
4
4
  /**
5
5
  * Pino logger provider implementation
6
6
  */
7
7
  export class PinoLoggerProvider {
8
+ static sharedPrettyTransport = null;
8
9
  pinoLogger;
9
10
  constructor(config) {
10
- this.pinoLogger = pino(this.buildPinoOptions(config));
11
+ const options = this.buildPinoOptions(config);
12
+ const destination = PinoLoggerProvider.resolveDestination(config.format);
13
+ this.pinoLogger = destination ? pino(options, destination) : pino(options);
11
14
  }
12
15
  shutdown() {
13
16
  return Promise.resolve(this.pinoLogger.flush());
@@ -41,25 +44,34 @@ export class PinoLoggerProvider {
41
44
  level: 'trace',
42
45
  ...config.options,
43
46
  };
44
- if (config.format === LogFormat.PRETTY) {
45
- baseOptions.transport = {
46
- target: 'pino-pretty',
47
- options: {
48
- colorize: true,
49
- colorizeObjects: true,
50
- timestampKey: 'time',
51
- translateTime: 'yyyy-mm-dd HH:MM:ss.l',
52
- ignore: 'pid,hostname,context,params,metadata',
53
- singleLine: true,
54
- messageFormat: '{if context}<{context}>: {end}{msg}',
55
- },
56
- };
57
- }
58
- else if (config.format === LogFormat.GCP_CLOUD_LOGGING) {
47
+ if (config.format === LogFormat.GCP_CLOUD_LOGGING) {
59
48
  return createGcpLoggingPinoConfig({}, {
60
49
  ...baseOptions,
61
50
  });
62
51
  }
63
52
  return baseOptions;
64
53
  }
54
+ static resolveDestination(format) {
55
+ if (format === LogFormat.PRETTY) {
56
+ return this.getSharedPrettyTransport();
57
+ }
58
+ return undefined;
59
+ }
60
+ static getSharedPrettyTransport() {
61
+ if (this.sharedPrettyTransport)
62
+ return this.sharedPrettyTransport;
63
+ this.sharedPrettyTransport = pino.transport({
64
+ target: 'pino-pretty',
65
+ options: {
66
+ colorize: true,
67
+ colorizeObjects: true,
68
+ timestampKey: 'time',
69
+ translateTime: 'yyyy-mm-dd HH:MM:ss.l',
70
+ ignore: 'pid,hostname,context,params,metadata',
71
+ singleLine: true,
72
+ messageFormat: '{if context}<{context}>: {end}{msg}',
73
+ },
74
+ });
75
+ return this.sharedPrettyTransport;
76
+ }
65
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owox/internal-helpers",
3
- "version": "0.11.0-next-20251025220131",
3
+ "version": "0.11.0-next-20251027113952",
4
4
  "description": "Internal helpers used by core OWOX packages",
5
5
  "type": "module",
6
6
  "author": "OWOX",