()
| 81 | } |
| 82 | |
| 83 | export default function logger(): Logger { |
| 84 | if (!LOGGER) { |
| 85 | let options: PinoConf; |
| 86 | let destinationStream: DestinationStream | undefined; |
| 87 | |
| 88 | const { appVersion, logLevel } = config(); |
| 89 | // Add appVersion to the base options |
| 90 | const baseOptions: PinoConf = { |
| 91 | level: logLevel, |
| 92 | base: { |
| 93 | "service.version": appVersion, |
| 94 | }, |
| 95 | }; |
| 96 | |
| 97 | if (config().prettyLogs) { |
| 98 | options = baseOptions; |
| 99 | destinationStream = pinoPretty({ |
| 100 | translateTime: "HH:MM:ss Z", |
| 101 | ignore: "pid,hostname", |
| 102 | sync: true, |
| 103 | }); |
| 104 | } else { |
| 105 | const { exportLogsHyperDx, hyperDxApiKey } = config(); |
| 106 | |
| 107 | options = baseOptions; |
| 108 | if (config().googleOps) { |
| 109 | Object.assign(options, googleOpsConfig); |
| 110 | } else if (exportLogsHyperDx && hyperDxApiKey) { |
| 111 | options.mixin = HyperDX.getPinoMixinFunction; |
| 112 | |
| 113 | options.transport = { |
| 114 | targets: [ |
| 115 | { |
| 116 | target: "@hyperdx/node-opentelemetry/build/src/otel-logger/pino", |
| 117 | options: { |
| 118 | apiKey: hyperDxApiKey, |
| 119 | service: getServiceName(), |
| 120 | }, |
| 121 | level: logLevel, |
| 122 | }, |
| 123 | ], |
| 124 | }; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | const l = pino(options, destinationStream); |
| 129 | LOGGER = l; |
| 130 | return l; |
| 131 | } |
| 132 | return LOGGER; |
| 133 | } |
no test coverage detected