@openhealth/oht-custom-parser-lib 0.3.4 → 0.3.6
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/util-ts/pinoLogger.js +28 -1
- package/dist/util-ts/pinoLogger.js.map +1 -1
- package/package.json +3 -2
- package/readme.md +5 -0
|
@@ -16,6 +16,14 @@ const SeverityLookup = {
|
|
|
16
16
|
warn: 'WARNING',
|
|
17
17
|
error: 'ERROR',
|
|
18
18
|
};
|
|
19
|
+
/** True when logs should be pretty-printed for terminal (local/dev). GCP/production keeps JSON. */
|
|
20
|
+
function usePrettyLogs() {
|
|
21
|
+
if (process.env.LOG_PRETTY === 'true')
|
|
22
|
+
return true;
|
|
23
|
+
if (process.env.LOG_PRETTY === 'false')
|
|
24
|
+
return false;
|
|
25
|
+
return process.env.NODE_ENV !== 'production';
|
|
26
|
+
}
|
|
19
27
|
// Define the default Pino configuration
|
|
20
28
|
const defaultPinoConfig = {
|
|
21
29
|
messageKey: 'message',
|
|
@@ -46,8 +54,27 @@ const defaultPinoConfig = {
|
|
|
46
54
|
}
|
|
47
55
|
},
|
|
48
56
|
};
|
|
57
|
+
/** Options for pino-pretty when running locally (readable terminal output). */
|
|
58
|
+
const prettyTransportOptions = {
|
|
59
|
+
target: 'pino-pretty',
|
|
60
|
+
options: {
|
|
61
|
+
colorize: true,
|
|
62
|
+
translateTime: 'SYS:HH:MM:ss',
|
|
63
|
+
messageKey: 'message',
|
|
64
|
+
singleLine: false,
|
|
65
|
+
errorLikeObjectKeys: ['err', 'error'],
|
|
66
|
+
ignore: 'pid,hostname',
|
|
67
|
+
},
|
|
68
|
+
};
|
|
49
69
|
// Export a function that creates a Pino logger instance with the provided configuration overrides
|
|
50
70
|
exports.default = (pinoConfigOverrides = {}) => {
|
|
51
|
-
|
|
71
|
+
const baseConfig = { ...defaultPinoConfig, ...pinoConfigOverrides };
|
|
72
|
+
if (usePrettyLogs()) {
|
|
73
|
+
return (0, pino_1.default)({
|
|
74
|
+
...baseConfig,
|
|
75
|
+
transport: prettyTransportOptions,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return (0, pino_1.default)(baseConfig);
|
|
52
79
|
};
|
|
53
80
|
//# sourceMappingURL=pinoLogger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pinoLogger.js","sourceRoot":"","sources":["../../util-ts/pinoLogger.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,qDAA+E;AAO/E,oCAAoC;AACpC,MAAM,cAAc,GAAuB;IACzC,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,SAAS;IAChB,OAAO,EAAE,OAAO;IAChB,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,SAAS;IACf,KAAK,EAAE,OAAO;CACf,CAAC;AAEF,wCAAwC;AACxC,MAAM,iBAAiB,GAAG;IACxB,UAAU,EAAE,SAAS;IACrB,UAAU,EAAE;QACV,KAAK,CAAC,KAAsB,EAAE,MAAW;YACvC,OAAO,EAAE,QAAQ,EAAE,cAAc,CAAC,KAAK,CAAC,IAAI,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QACzE,CAAC;KACF;IACD,WAAW,EAAE;QACX,KAAK,EAAE,cAAI,CAAC,cAAc,CAAC,GAAG,EAAE,6BAA6B;KAC9D;IACD,MAAM,EAAE;QACN,KAAK,EAAE,IAAA,kCAAiB,GAAE;QAC1B,MAAM,EAAE,YAAY;KACrB;IACD,KAAK,EAAE;QACL,SAAS,CAAC,IAA4B,EAAE,MAAgB;YACtD,IAAI,CAAC;gBACH,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;oBACvE,MAAM,SAAS,GAAG,IAAA,yCAAwB,EAAC,I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AU;YACb,SAAS,EAAE,sBAAsB;SAClC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAA,cAAI,EAAC,UAAU,CAAC,CAAC;AAC1B,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openhealth/oht-custom-parser-lib",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Shared nodejs lib with with reusable functions",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"jsonata": "^2.1.0",
|
|
24
24
|
"moment": "^2.30.1",
|
|
25
25
|
"mongodb": "^6.3.0",
|
|
26
|
-
"pino": "^8.19.0"
|
|
26
|
+
"pino": "^8.19.0",
|
|
27
|
+
"pino-pretty": "^11.3.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@types/jest": "^29.5.14",
|
package/readme.md
CHANGED
|
@@ -33,6 +33,11 @@ After installing, you can import and use the library in your cloud functions:
|
|
|
33
33
|
const { connectToMongoDB } = require('oht-custom-parser-lib');
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
## Logging
|
|
37
|
+
|
|
38
|
+
- **Production / GCP**: Logs are emitted as JSON (one line per log) for Cloud Logging.
|
|
39
|
+
- **Local / development**: When `NODE_ENV !== 'production'`, logs are pretty-printed in the terminal (colors, timestamps, readable structure). You can override: `LOG_PRETTY=true` to force pretty output, or `LOG_PRETTY=false` to force JSON when not in production.
|
|
40
|
+
|
|
36
41
|
## Development
|
|
37
42
|
|
|
38
43
|
### Patch Versions
|