@justair/justair-library 6.5.0 → 6.6.0-alpha.b0ec65c
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/README.md +22 -0
- package/dist/config/logger.d.ts +7 -0
- package/dist/config/logger.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/config/logger.js +26 -1
package/README.md
CHANGED
|
@@ -32,6 +32,28 @@ npm set //registry.npmjs.org/:_authToken=YOUR_ACCESS_TOKEN
|
|
|
32
32
|
import { Monitors, Measurements, createLoggerInstance, Database } from '@justair/justair-library';
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
## Logging
|
|
36
|
+
|
|
37
|
+
The logger created by `createLoggerInstance` reads its threshold from the `LOG_LEVEL` environment
|
|
38
|
+
variable, applied to both the console and Datadog transports. When `LOG_LEVEL` is unset it defaults
|
|
39
|
+
to `info`, so `logger.debug(...)` calls are dropped in steady state and surface only when you opt in.
|
|
40
|
+
|
|
41
|
+
Valid levels (Winston syslog): `emerg`, `alert`, `crit`, `error`, `warning`, `notice`, `info`,
|
|
42
|
+
`debug`. An unset or unrecognized value falls back to `info` (a `warning` is logged for an invalid
|
|
43
|
+
value rather than crashing the service).
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# Locally: surface all debug output
|
|
47
|
+
LOG_LEVEL=debug npm run dev
|
|
48
|
+
|
|
49
|
+
# Deployed (Heroku): set the config var, then restart the dyno
|
|
50
|
+
heroku config:set LOG_LEVEL=debug -a <app-name>
|
|
51
|
+
|
|
52
|
+
# Cloud Run / GKE / Lambda: set LOG_LEVEL=debug in the service's environment, then redeploy
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Unset `LOG_LEVEL` (or set it back to `info`) to return to normal volume.
|
|
56
|
+
|
|
35
57
|
## Constants
|
|
36
58
|
|
|
37
59
|
The library exposes two entry points — one for Node.js services (models + constants) and one
|
package/dist/config/logger.d.ts
CHANGED
|
@@ -7,6 +7,13 @@ declare class CustomLogger {
|
|
|
7
7
|
DATADOG_API_KEY: any;
|
|
8
8
|
APPLICATION_NAME: any;
|
|
9
9
|
logger: import("winston").Logger;
|
|
10
|
+
_resolveLogLevel(): {
|
|
11
|
+
level: string;
|
|
12
|
+
invalidValue?: undefined;
|
|
13
|
+
} | {
|
|
14
|
+
level: string;
|
|
15
|
+
invalidValue: string;
|
|
16
|
+
};
|
|
10
17
|
_createLogger(): import("winston").Logger;
|
|
11
18
|
getLogger(): import("winston").Logger;
|
|
12
19
|
_getServiceMetadata(): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/config/logger.js"],"names":[],"mappings":";AAGA;IACE;;;OAIC;IAHC,qBAAsC;IACtC,sBAAwC;IACxC,iCAAkC;
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/config/logger.js"],"names":[],"mappings":";AAGA;IACE;;;OAIC;IAHC,qBAAsC;IACtC,sBAAwC;IACxC,iCAAkC;IAKpC;;;;;;MASC;IAED,0CAuCC;IAED,sCAEC;IAED;;;;;;;;;;;;;;MAgBC;IAED,uCAMC;IAED,sDAOC;IAED,uDAYC;IAED,wCAOC;IAED,4BAsCC;CACF"}
|
package/package.json
CHANGED
package/src/config/logger.js
CHANGED
|
@@ -8,6 +8,19 @@ class CustomLogger {
|
|
|
8
8
|
this.logger = this._createLogger();
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
// Resolve the logger threshold from LOG_LEVEL. Falls back to 'info' (Winston's
|
|
12
|
+
// default) when unset or invalid so a typo can't crash every consuming service.
|
|
13
|
+
_resolveLogLevel() {
|
|
14
|
+
const requested = process.env.LOG_LEVEL;
|
|
15
|
+
if (!requested) {
|
|
16
|
+
return { level: 'info' };
|
|
17
|
+
}
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(config.syslog.levels, requested)) {
|
|
19
|
+
return { level: requested };
|
|
20
|
+
}
|
|
21
|
+
return { level: 'info', invalidValue: requested };
|
|
22
|
+
}
|
|
23
|
+
|
|
11
24
|
_createLogger() {
|
|
12
25
|
const httpTransportOptions = {
|
|
13
26
|
host: 'http-intake.logs.us5.datadoghq.com',
|
|
@@ -15,7 +28,10 @@ class CustomLogger {
|
|
|
15
28
|
ssl: true
|
|
16
29
|
};
|
|
17
30
|
|
|
18
|
-
|
|
31
|
+
const { level, invalidValue } = this._resolveLogLevel();
|
|
32
|
+
|
|
33
|
+
const logger = createLogger({
|
|
34
|
+
level,
|
|
19
35
|
levels: config.syslog.levels,
|
|
20
36
|
exitOnError: false,
|
|
21
37
|
format: combine(
|
|
@@ -35,6 +51,15 @@ class CustomLogger {
|
|
|
35
51
|
new transports.Http(httpTransportOptions)
|
|
36
52
|
]
|
|
37
53
|
});
|
|
54
|
+
|
|
55
|
+
if (invalidValue) {
|
|
56
|
+
logger.warning('Ignoring invalid LOG_LEVEL, defaulting to info', {
|
|
57
|
+
invalidValue,
|
|
58
|
+
validLevels: Object.keys(config.syslog.levels)
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return logger;
|
|
38
63
|
}
|
|
39
64
|
|
|
40
65
|
getLogger() {
|