@voiceflow/logger 1.6.2 → 2.0.0

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.
Files changed (50) hide show
  1. package/README.md +14 -45
  2. package/build/detailed.logger.d.ts +4 -0
  3. package/build/detailed.logger.js +15 -0
  4. package/build/detailed.logger.js.map +1 -0
  5. package/build/http.logger.d.ts +4 -0
  6. package/build/http.logger.js +30 -0
  7. package/build/http.logger.js.map +1 -0
  8. package/build/inline.logger.d.ts +4 -0
  9. package/build/inline.logger.js +18 -0
  10. package/build/inline.logger.js.map +1 -0
  11. package/build/json.logger.d.ts +4 -0
  12. package/build/json.logger.js +12 -0
  13. package/build/json.logger.js.map +1 -0
  14. package/build/log-format.enum.d.ts +5 -0
  15. package/build/log-format.enum.js +10 -0
  16. package/build/log-format.enum.js.map +1 -0
  17. package/build/log-level.enum.d.ts +8 -0
  18. package/build/log-level.enum.js +13 -0
  19. package/build/log-level.enum.js.map +1 -0
  20. package/build/logger-options.interface.d.ts +6 -0
  21. package/build/logger-options.interface.js +3 -0
  22. package/build/logger-options.interface.js.map +1 -0
  23. package/build/logger.d.ts +3 -0
  24. package/build/logger.js +30 -0
  25. package/build/logger.js.map +1 -0
  26. package/build/main.d.ts +9 -0
  27. package/build/main.js +25 -0
  28. package/build/main.js.map +1 -0
  29. package/build/utils.d.ts +5 -0
  30. package/build/utils.js +17 -0
  31. package/build/utils.js.map +1 -0
  32. package/package.json +40 -44
  33. package/build/index.d.ts +0 -4
  34. package/build/index.js +0 -13
  35. package/build/index.js.map +0 -1
  36. package/build/lib/constants.d.ts +0 -23
  37. package/build/lib/constants.js +0 -25
  38. package/build/lib/constants.js.map +0 -1
  39. package/build/lib/createMiddleware.d.ts +0 -9
  40. package/build/lib/createMiddleware.js +0 -51
  41. package/build/lib/createMiddleware.js.map +0 -1
  42. package/build/lib/createTraced.d.ts +0 -13
  43. package/build/lib/createTraced.js +0 -46
  44. package/build/lib/createTraced.js.map +0 -1
  45. package/build/lib/logger.d.ts +0 -24
  46. package/build/lib/logger.js +0 -76
  47. package/build/lib/logger.js.map +0 -1
  48. package/build/lib/utils.d.ts +0 -37
  49. package/build/lib/utils.js +0 -44
  50. package/build/lib/utils.js.map +0 -1
package/README.md CHANGED
@@ -1,57 +1,26 @@
1
1
  [![circle ci](https://circleci.com/gh/voiceflow/logger.svg?style=shield&circle-token=8c4e4ce8d04d87f16e903bd7e1ccab194a118262)](https://circleci.com/gh/voiceflow/logger)
2
2
  [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=voiceflow_logger&metric=coverage)](https://sonarcloud.io/dashboard?id=voiceflow_logger)
3
3
  [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=voiceflow_logger&metric=alert_status)](https://sonarcloud.io/dashboard?id=voiceflow_logger)
4
- # logger
5
-
6
- Author: Frank Gu <<frank@voicelfow.com>>
7
- Date: Dec 11, 2019
8
4
 
9
- A logging package for VERY fast and useful JSON logging.
5
+ # logger
10
6
 
11
- - All log entries go to `process.stdout`
12
- - Minimal overhead and no logger hierarchies
13
- - Multiple instantiations allowed
7
+ A standardized package for logging built on `pino`.
14
8
 
15
9
  ## Usage
16
10
 
17
- ```javascript
18
- const Logger = require('@voiceflow/logger').default;
19
- // or
20
- import Logger from '@voiceflow/logger';
21
-
22
- const defaultOptions = {
23
- level: 'info',
24
- pretty: false,
25
- };
26
-
27
- const overrideOptions = {
28
- level: 'trace', // Minimum log-level to be printed
29
- pretty: true, // Pretty print
30
- };
31
-
32
- const defaultLogger = new Logger(); // Default options
33
- const customLogger = new Logger(overrideOptions);
34
-
35
- defaultLogger.trace('this is a trace');
36
- defaultLogger.debug('this is a debug');
37
- defaultLogger.info('this is an info');
38
- defaultLogger.warn('this is a warning');
39
- defaultLogger.error('this is an error');
40
- defaultLogger.fatal('this is a fatal');
41
-
42
- customLogger.trace('this is a trace');
43
- customLogger.debug('this is a debug');
44
- customLogger.info('this is an info');
45
- customLogger.warn('this is a warning');
46
- customLogger.error('this is an error');
47
- customLogger.fatal('this is a fatal');
48
- ```
11
+ ```ts
12
+ import { createLogger, LogLevel, LogFormat } from '@voiceflow/logger';
49
13
 
50
- ### Development Assitance
14
+ const logger = createLogger({ format: LogFormat.JSON, level: LogLevel.INFO });
51
15
 
52
- - For `warn` logs, the calling function and line number is included
53
- - For `error` and `fatal` logs, the full call-stack is included
16
+ const inlineLogger = createLogger({ format: LogFormat.INLINE, level: LogLevel.WARN });
54
17
 
55
- ### Pretty Printing
18
+ const detailedLogger = createLogger({ format: LogFormat.DETAILED, level: LogLevel.TRACE });
56
19
 
57
- Pretty printing will add colors, parse unix epoch timestamps into UTC time.
20
+ logger.trace('this is a trace log');
21
+ logger.debug('this is a debug log');
22
+ logger.info('this is an info log');
23
+ logger.warn('this is a warning log');
24
+ logger.error('this is an error log');
25
+ logger.fatal('this is a fatal log');
26
+ ```
@@ -0,0 +1,4 @@
1
+ import pino from 'pino';
2
+ import { LogLevel } from './log-level.enum';
3
+ export declare const createDetailedConfig: (level: LogLevel) => pino.LoggerOptions;
4
+ export declare const createDetailedLogger: (level: LogLevel) => import("pino").Logger<pino.LoggerOptions>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createDetailedLogger = exports.createDetailedConfig = void 0;
7
+ const pino_1 = __importDefault(require("pino"));
8
+ const createDetailedConfig = (level) => ({
9
+ level,
10
+ transport: { target: 'pino-pretty' },
11
+ });
12
+ exports.createDetailedConfig = createDetailedConfig;
13
+ const createDetailedLogger = (level) => (0, pino_1.default)((0, exports.createDetailedConfig)(level));
14
+ exports.createDetailedLogger = createDetailedLogger;
15
+ //# sourceMappingURL=detailed.logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detailed.logger.js","sourceRoot":"","sources":["../src/detailed.logger.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAIjB,MAAM,oBAAoB,GAAG,CAAC,KAAe,EAAsB,EAAE,CAAC,CAAC;IAC5E,KAAK;IACL,SAAS,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE;CACrC,CAAC,CAAC;AAHU,QAAA,oBAAoB,wBAG9B;AAEI,MAAM,oBAAoB,GAAG,CAAC,KAAe,EAAE,EAAE,CAAC,IAAA,cAAI,EAAC,IAAA,4BAAoB,EAAC,KAAK,CAAC,CAAC,CAAC;AAA9E,QAAA,oBAAoB,wBAA0D"}
@@ -0,0 +1,4 @@
1
+ import { Options } from 'pino-http';
2
+ import { LoggerOptions } from './logger-options.interface';
3
+ export declare const createHTTPConfig: ({ format, level }: LoggerOptions) => Options;
4
+ export declare const createHTTPLogger: (options: LoggerOptions) => import("pino-http").HttpLogger;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createHTTPLogger = exports.createHTTPConfig = void 0;
7
+ /* eslint-disable sonarjs/no-nested-template-literals */
8
+ const colorette_1 = require("colorette");
9
+ const pino_http_1 = __importDefault(require("pino-http"));
10
+ const ts_pattern_1 = require("ts-pattern");
11
+ const detailed_logger_1 = require("./detailed.logger");
12
+ const inline_logger_1 = require("./inline.logger");
13
+ const json_logger_1 = require("./json.logger");
14
+ const log_format_enum_1 = require("./log-format.enum");
15
+ const log_level_enum_1 = require("./log-level.enum");
16
+ const utils_1 = require("./utils");
17
+ const createHTTPConfig = ({ format, level }) => (Object.assign({ customLogLevel: (_req, res) => {
18
+ if ((0, utils_1.isWarnResponse)(res))
19
+ return log_level_enum_1.LogLevel.WARN;
20
+ if ((0, utils_1.isErrorResponse)(res))
21
+ return log_level_enum_1.LogLevel.ERROR;
22
+ return log_level_enum_1.LogLevel.INFO;
23
+ } }, (0, ts_pattern_1.match)(format)
24
+ .with(log_format_enum_1.LogFormat.INLINE, () => (Object.assign({ customSuccessMessage: (req, res) => `${(0, utils_1.getColorizer)(res)(`(${res.statusCode})`)} ${(0, colorette_1.white)(`${req.method} ${req.url}`)}`, customErrorMessage: (req, res) => { var _a; return `${(0, utils_1.getColorizer)(res)(`(${res.statusCode})`)} ${(0, colorette_1.white)(`${req.method} ${req.url} -`)} ${(_a = res.err) === null || _a === void 0 ? void 0 : _a.message}`; } }, (0, inline_logger_1.createInlineConfig)(level))))
25
+ .with(log_format_enum_1.LogFormat.DETAILED, () => (0, detailed_logger_1.createDetailedConfig)(level))
26
+ .otherwise(() => (0, json_logger_1.createJSONConfig)(level))));
27
+ exports.createHTTPConfig = createHTTPConfig;
28
+ const createHTTPLogger = (options) => (0, pino_http_1.default)((0, exports.createHTTPConfig)(options));
29
+ exports.createHTTPLogger = createHTTPLogger;
30
+ //# sourceMappingURL=http.logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.logger.js","sourceRoot":"","sources":["../src/http.logger.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAwD;AACxD,yCAAkC;AAClC,0DAA8C;AAC9C,2CAAmC;AAEnC,uDAAyD;AACzD,mDAAqD;AACrD,+CAAiD;AACjD,uDAA8C;AAC9C,qDAA4C;AAE5C,mCAAwE;AAEjE,MAAM,gBAAgB,GAAG,CAAC,EAAE,MAAM,EAAE,KAAK,EAAiB,EAAW,EAAE,CAAC,iBAC7E,cAAc,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;QAC5B,IAAI,IAAA,sBAAc,EAAC,GAAG,CAAC;YAAE,OAAO,yBAAQ,CAAC,IAAI,CAAC;QAC9C,IAAI,IAAA,uBAAe,EAAC,GAAG,CAAC;YAAE,OAAO,yBAAQ,CAAC,KAAK,CAAC;QAChD,OAAO,yBAAQ,CAAC,IAAI,CAAC;IACvB,CAAC,IAEE,IAAA,kBAAK,EAAqB,MAAM,CAAC;KACjC,IAAI,CAAC,2BAAS,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,iBAC5B,oBAAoB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,IAAA,oBAAY,EAAC,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,UAAU,GAAG,CAAC,IAAI,IAAA,iBAAK,EAAC,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,EACtH,kBAAkB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,WAAC,OAAA,GAAG,IAAA,oBAAY,EAAC,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,UAAU,GAAG,CAAC,IAAI,IAAA,iBAAK,EAAC,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,MAAA,GAAG,CAAC,GAAG,0CAAE,OAAO,EAAE,CAAA,EAAA,IACvI,IAAA,kCAAkB,EAAC,KAAK,CAAC,EAC5B,CAAC;KACF,IAAI,CAAC,2BAAS,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAA,sCAAoB,EAAC,KAAK,CAAC,CAAC;KAC3D,SAAS,CAAC,GAAG,EAAE,CAAC,IAAA,8BAAgB,EAAC,KAAK,CAAC,CAAC,EAC3C,CAAC;AAfU,QAAA,gBAAgB,oBAe1B;AAEI,MAAM,gBAAgB,GAAG,CAAC,OAAsB,EAAE,EAAE,CAAC,IAAA,mBAAQ,EAAC,IAAA,wBAAgB,EAAC,OAAO,CAAC,CAAC,CAAC;AAAnF,QAAA,gBAAgB,oBAAmE"}
@@ -0,0 +1,4 @@
1
+ import pino from 'pino';
2
+ import { LogLevel } from './log-level.enum';
3
+ export declare const createInlineConfig: (level: LogLevel) => pino.LoggerOptions;
4
+ export declare const createInlineLogger: (level: LogLevel) => import("pino").Logger<pino.LoggerOptions>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createInlineLogger = exports.createInlineConfig = void 0;
7
+ const pino_1 = __importDefault(require("pino"));
8
+ const createInlineConfig = (level) => ({
9
+ level,
10
+ transport: {
11
+ target: 'pino-pretty',
12
+ options: { include: 'time,level' },
13
+ },
14
+ });
15
+ exports.createInlineConfig = createInlineConfig;
16
+ const createInlineLogger = (level) => (0, pino_1.default)((0, exports.createInlineConfig)(level));
17
+ exports.createInlineLogger = createInlineLogger;
18
+ //# sourceMappingURL=inline.logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline.logger.js","sourceRoot":"","sources":["../src/inline.logger.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAIjB,MAAM,kBAAkB,GAAG,CAAC,KAAe,EAAsB,EAAE,CAAC,CAAC;IAC1E,KAAK;IACL,SAAS,EAAE;QACT,MAAM,EAAE,aAAa;QACrB,OAAO,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE;KACnC;CACF,CAAC,CAAC;AANU,QAAA,kBAAkB,sBAM5B;AAEI,MAAM,kBAAkB,GAAG,CAAC,KAAe,EAAE,EAAE,CAAC,IAAA,cAAI,EAAC,IAAA,0BAAkB,EAAC,KAAK,CAAC,CAAC,CAAC;AAA1E,QAAA,kBAAkB,sBAAwD"}
@@ -0,0 +1,4 @@
1
+ import pino from 'pino';
2
+ import { LogLevel } from './log-level.enum';
3
+ export declare const createJSONConfig: (level: LogLevel) => pino.LoggerOptions;
4
+ export declare const createJSONLogger: (level: LogLevel) => import("pino").Logger<pino.LoggerOptions>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createJSONLogger = exports.createJSONConfig = void 0;
7
+ const pino_1 = __importDefault(require("pino"));
8
+ const createJSONConfig = (level) => ({ level });
9
+ exports.createJSONConfig = createJSONConfig;
10
+ const createJSONLogger = (level) => (0, pino_1.default)((0, exports.createJSONConfig)(level));
11
+ exports.createJSONLogger = createJSONLogger;
12
+ //# sourceMappingURL=json.logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.logger.js","sourceRoot":"","sources":["../src/json.logger.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAIjB,MAAM,gBAAgB,GAAG,CAAC,KAAe,EAAsB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AAAxE,QAAA,gBAAgB,oBAAwD;AAE9E,MAAM,gBAAgB,GAAG,CAAC,KAAe,EAAE,EAAE,CAAC,IAAA,cAAI,EAAC,IAAA,wBAAgB,EAAC,KAAK,CAAC,CAAC,CAAC;AAAtE,QAAA,gBAAgB,oBAAsD"}
@@ -0,0 +1,5 @@
1
+ export declare enum LogFormat {
2
+ DETAILED = "detailed",
3
+ INLINE = "inline",
4
+ JSON = "json"
5
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogFormat = void 0;
4
+ var LogFormat;
5
+ (function (LogFormat) {
6
+ LogFormat["DETAILED"] = "detailed";
7
+ LogFormat["INLINE"] = "inline";
8
+ LogFormat["JSON"] = "json";
9
+ })(LogFormat = exports.LogFormat || (exports.LogFormat = {}));
10
+ //# sourceMappingURL=log-format.enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-format.enum.js","sourceRoot":"","sources":["../src/log-format.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,kCAAqB,CAAA;IACrB,8BAAiB,CAAA;IACjB,0BAAa,CAAA;AACf,CAAC,EAJW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAIpB"}
@@ -0,0 +1,8 @@
1
+ export declare enum LogLevel {
2
+ FATAL = "fatal",
3
+ ERROR = "error",
4
+ WARN = "warn",
5
+ INFO = "info",
6
+ DEBUG = "debug",
7
+ TRACE = "trace"
8
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogLevel = void 0;
4
+ var LogLevel;
5
+ (function (LogLevel) {
6
+ LogLevel["FATAL"] = "fatal";
7
+ LogLevel["ERROR"] = "error";
8
+ LogLevel["WARN"] = "warn";
9
+ LogLevel["INFO"] = "info";
10
+ LogLevel["DEBUG"] = "debug";
11
+ LogLevel["TRACE"] = "trace";
12
+ })(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
13
+ //# sourceMappingURL=log-level.enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-level.enum.js","sourceRoot":"","sources":["../src/log-level.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,yBAAa,CAAA;IACb,2BAAe,CAAA;IACf,2BAAe,CAAA;AACjB,CAAC,EAPW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAOnB"}
@@ -0,0 +1,6 @@
1
+ import { LogFormat } from './log-format.enum';
2
+ import { LogLevel } from './log-level.enum';
3
+ export interface LoggerOptions {
4
+ level: LogLevel;
5
+ format: LogFormat;
6
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=logger-options.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger-options.interface.js","sourceRoot":"","sources":["../src/logger-options.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import { LoggerOptions } from './logger-options.interface';
2
+ export declare const DEFAULT_OPTIONS: LoggerOptions;
3
+ export declare const createLogger: (options?: Partial<LoggerOptions>) => import("pino").Logger<import("pino").default.LoggerOptions>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createLogger = exports.DEFAULT_OPTIONS = void 0;
7
+ const lodash_merge_1 = __importDefault(require("lodash.merge"));
8
+ const detailed_logger_1 = require("./detailed.logger");
9
+ const inline_logger_1 = require("./inline.logger");
10
+ const json_logger_1 = require("./json.logger");
11
+ const log_format_enum_1 = require("./log-format.enum");
12
+ const log_level_enum_1 = require("./log-level.enum");
13
+ exports.DEFAULT_OPTIONS = {
14
+ format: log_format_enum_1.LogFormat.JSON,
15
+ level: log_level_enum_1.LogLevel.INFO,
16
+ };
17
+ const createLogger = (options = {}) => {
18
+ const { format, level } = (0, lodash_merge_1.default)({}, exports.DEFAULT_OPTIONS, options);
19
+ switch (format) {
20
+ case log_format_enum_1.LogFormat.DETAILED:
21
+ return (0, detailed_logger_1.createDetailedLogger)(level);
22
+ case log_format_enum_1.LogFormat.INLINE:
23
+ return (0, inline_logger_1.createInlineLogger)(level);
24
+ case log_format_enum_1.LogFormat.JSON:
25
+ default:
26
+ return (0, json_logger_1.createJSONLogger)(level);
27
+ }
28
+ };
29
+ exports.createLogger = createLogger;
30
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAkC;AAElC,uDAAyD;AACzD,mDAAqD;AACrD,+CAAiD;AACjD,uDAA8C;AAC9C,qDAA4C;AAG/B,QAAA,eAAe,GAAkB;IAC5C,MAAM,EAAE,2BAAS,CAAC,IAAI;IACtB,KAAK,EAAE,yBAAQ,CAAC,IAAI;CACrB,CAAC;AAEK,MAAM,YAAY,GAAG,CAAC,UAAkC,EAAE,EAAE,EAAE;IACnE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,sBAAM,EAAC,EAAE,EAAE,uBAAe,EAAE,OAAO,CAAC,CAAC;IAE/D,QAAQ,MAAM,EAAE;QACd,KAAK,2BAAS,CAAC,QAAQ;YACrB,OAAO,IAAA,sCAAoB,EAAC,KAAK,CAAC,CAAC;QACrC,KAAK,2BAAS,CAAC,MAAM;YACnB,OAAO,IAAA,kCAAkB,EAAC,KAAK,CAAC,CAAC;QACnC,KAAK,2BAAS,CAAC,IAAI,CAAC;QACpB;YACE,OAAO,IAAA,8BAAgB,EAAC,KAAK,CAAC,CAAC;KAClC;AACH,CAAC,CAAC;AAZW,QAAA,YAAY,gBAYvB"}
@@ -0,0 +1,9 @@
1
+ export * from './detailed.logger';
2
+ export * from './http.logger';
3
+ export * from './inline.logger';
4
+ export * from './json.logger';
5
+ export * from './log-format.enum';
6
+ export * from './log-level.enum';
7
+ export * from './logger';
8
+ export * from './logger-options.interface';
9
+ export type { Logger } from 'pino';
package/build/main.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./detailed.logger"), exports);
18
+ __exportStar(require("./http.logger"), exports);
19
+ __exportStar(require("./inline.logger"), exports);
20
+ __exportStar(require("./json.logger"), exports);
21
+ __exportStar(require("./log-format.enum"), exports);
22
+ __exportStar(require("./log-level.enum"), exports);
23
+ __exportStar(require("./logger"), exports);
24
+ __exportStar(require("./logger-options.interface"), exports);
25
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,gDAA8B;AAC9B,kDAAgC;AAChC,gDAA8B;AAC9B,oDAAkC;AAClC,mDAAiC;AACjC,2CAAyB;AACzB,6DAA2C"}
@@ -0,0 +1,5 @@
1
+ /// <reference types="colorette" />
2
+ import { ServerResponse } from 'node:http';
3
+ export declare const isWarnResponse: (res: ServerResponse) => boolean;
4
+ export declare const isErrorResponse: (res: ServerResponse) => boolean | Error;
5
+ export declare const getColorizer: (res: ServerResponse) => import("colorette").Color;
package/build/utils.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getColorizer = exports.isErrorResponse = exports.isWarnResponse = void 0;
4
+ const colorette_1 = require("colorette");
5
+ const isWarnResponse = (res) => res.statusCode >= 400 && res.statusCode <= 499;
6
+ exports.isWarnResponse = isWarnResponse;
7
+ const isErrorResponse = (res) => res.err || (res.statusCode >= 500 && res.statusCode <= 599);
8
+ exports.isErrorResponse = isErrorResponse;
9
+ const getColorizer = (res) => {
10
+ if ((0, exports.isWarnResponse)(res))
11
+ return colorette_1.yellow;
12
+ if ((0, exports.isErrorResponse)(res))
13
+ return colorette_1.red;
14
+ return colorette_1.green;
15
+ };
16
+ exports.getColorizer = getColorizer;
17
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAEA,yCAA+C;AAExC,MAAM,cAAc,GAAG,CAAC,GAAmB,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,IAAI,GAAG,IAAI,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC;AAAzF,QAAA,cAAc,kBAA2E;AAC/F,MAAM,eAAe,GAAG,CAAC,GAAmB,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,IAAI,GAAG,IAAI,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,CAAC;AAAvG,QAAA,eAAe,mBAAwF;AAC7G,MAAM,YAAY,GAAG,CAAC,GAAmB,EAAE,EAAE;IAClD,IAAI,IAAA,sBAAc,EAAC,GAAG,CAAC;QAAE,OAAO,kBAAM,CAAC;IACvC,IAAI,IAAA,uBAAe,EAAC,GAAG,CAAC;QAAE,OAAO,eAAG,CAAC;IACrC,OAAO,iBAAK,CAAC;AACf,CAAC,CAAC;AAJW,QAAA,YAAY,gBAIvB"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@voiceflow/logger",
3
3
  "description": "Common logger for Voiceflow backend microservices",
4
- "version": "1.6.2",
4
+ "version": "2.0.0",
5
5
  "author": "Frank Gu <frank@voiceflow.com>",
6
6
  "bugs": {
7
7
  "url": "https://github.com/voiceflow/logger/issues"
@@ -12,45 +12,41 @@
12
12
  }
13
13
  },
14
14
  "dependencies": {
15
- "@types/cls-hooked": "^4.3.1",
16
- "@types/express-pino-logger": "^4.0.2",
17
- "@voiceflow/pino": "6.11.2",
18
- "@voiceflow/pino-pretty": "4.4.0",
19
- "@zerollup/ts-transform-paths": "^1.7.18",
20
- "cls-hooked": "^4.2.2",
21
- "nanoid": "^3.1.20",
22
- "pino-http": "5.3.0"
15
+ "colorette": "2.0.19",
16
+ "lodash.merge": "4.6.2",
17
+ "pino": "8.7.0",
18
+ "pino-http": "8.2.1",
19
+ "pino-pretty": "9.1.1",
20
+ "ts-pattern": "^4.0.5"
23
21
  },
24
22
  "devDependencies": {
25
- "@commitlint/cli": "^11.0.0",
26
- "@commitlint/config-conventional": "^11.0.0",
27
- "@istanbuljs/nyc-config-typescript": "^1.0.1",
28
- "@types/chai": "^4.2.11",
29
- "@types/mocha": "^8.0.0",
30
- "@typescript-eslint/eslint-plugin": "^3.6.1",
31
- "@typescript-eslint/parser": "^3.6.1",
23
+ "@commitlint/cli": "17.1.2",
24
+ "@istanbuljs/nyc-config-typescript": "1.0.2",
25
+ "@types/chai": "4.3.3",
26
+ "@types/lodash.merge": "^4.6.7",
27
+ "@types/mocha": "9.1.1",
32
28
  "@voiceflow/commitlint-config": "2.0.0",
33
- "@voiceflow/eslint-config": "6.0.0",
34
- "@voiceflow/git-branch-check": "1.2.3",
35
- "@voiceflow/prettier-config": "1.0.6",
36
- "chai": "^4.2.0",
37
- "commitizen": "^4.2.3",
38
- "cz-conventional-changelog": "3.3.0",
39
- "depcheck": "^1.3.1",
40
- "eslint": "^7.32.0",
29
+ "@voiceflow/eslint-config": "7.0.0",
30
+ "@voiceflow/git-branch-check": "1.4.0",
31
+ "@voiceflow/prettier-config": "1.2.1",
32
+ "@voiceflow/semantic-release-config": "1.1.0",
33
+ "@voiceflow/tsconfig": "1.4.8",
34
+ "chai": "4.3.6",
35
+ "commitizen": "4.2.5",
36
+ "cz-conventional-changelog": "^3.3.0",
37
+ "depcheck": "^1.4.3",
38
+ "eslint": "8.23.1",
41
39
  "eslint-output": "^3.0.1",
42
40
  "fixpack": "^4.0.0",
43
- "husky": "^4.3.8",
44
- "lint-staged": "^10.5.3",
45
- "mocha": "^6.1.4",
41
+ "husky": "8.0.1",
42
+ "istanbul": "^0.4.5",
43
+ "lint-staged": "13.0.3",
44
+ "mocha": "10.0.0",
46
45
  "nyc": "^15.1.0",
47
- "prettier": "^1.18.2",
48
- "prettier-eslint-cli": "^5.0.0",
49
- "source-map-support": "^0.5.19",
50
- "ts-mocha": "^7.0.0",
51
- "ts-node": "^8.10.2",
52
- "ttypescript": "^1.5.10",
53
- "typescript": "^3.9.6"
46
+ "prettier": "2.7.1",
47
+ "ts-mocha": "10.0.0",
48
+ "tsc-alias": "1.7.0",
49
+ "typescript": "4.8.3"
54
50
  },
55
51
  "files": [
56
52
  "build/"
@@ -60,24 +56,24 @@
60
56
  "voiceflow"
61
57
  ],
62
58
  "license": "ISC",
63
- "main": "build/index.js",
59
+ "main": "build/main.js",
64
60
  "prettier": "@voiceflow/prettier-config",
65
61
  "repository": "git@github.com:voiceflow/logger.git",
66
62
  "scripts": {
67
- "build": "yarn clean && ttsc --project ./tsconfig.build.json",
63
+ "build": "yarn clean && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
68
64
  "clean": "rimraf build",
69
65
  "commit": "cz",
70
66
  "eslint-output": "eslint-output",
71
- "lint": "eslint \"./**/*.{js,ts}\"",
72
- "lint:fix": "yarn lint --fix",
67
+ "lint": "eslint '**/*.{js,ts}'",
73
68
  "lint:output": "yarn run eslint-output --quiet \"**/*.{js,ts}\"",
74
- "lint:quiet": "yarn lint --quiet",
75
69
  "lint:report": "yarn lint:output",
70
+ "tdd": "yarn test --watch",
76
71
  "test": "yarn test:run",
77
72
  "test:dependencies": "depcheck",
78
- "test:integration": "NODE_ENV=test nyc --report-dir nyc_coverage_integration ts-mocha --paths --opts ./config/tests/mocha.opts 'tests/**/*.it.{ts,js}'",
79
- "test:run": "NODE_ENV=test nyc ts-mocha --paths --opts ./config/tests/mocha.opts 'tests/**/*.{unit,it}.{ts,js}'",
80
- "test:single": "NODE_ENV=test nyc ts-mocha --paths --opts ./config/tests/mocha.opts",
81
- "test:unit": "NODE_ENV=test nyc --report-dir=nyc_coverage_unit ts-mocha --paths --opts ./config/tests/mocha.opts 'tests/**/*.unit.{ts,js}'"
82
- }
73
+ "test:integration": "NODE_ENV=test nyc --report-dir nyc_coverage_integration ts-mocha --paths --config ./config/test/.mocharc.yml 'test/**/*.it.ts'",
74
+ "test:run": "NODE_ENV=test nyc ts-mocha --paths --config ./config/test/.mocharc.yml 'test/**/*.{unit,it}.ts'",
75
+ "test:single": "NODE_ENV=test ts-mocha --paths --config ./config/test/.mocharc.yml",
76
+ "test:unit": "NODE_ENV=test nyc --report-dir=nyc_coverage_unit ts-mocha --paths --config ./config/test/.mocharc.yml 'test/**/*.unit.ts'"
77
+ },
78
+ "types": "build/main.d.ts"
83
79
  }
package/build/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import Logger from "./lib/logger";
2
- export { Level as LogLevel, MiddlewareVerbosity } from "./lib/constants";
3
- export { Logger };
4
- export default Logger;
package/build/index.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Logger = void 0;
7
- const logger_1 = __importDefault(require("./lib/logger"));
8
- exports.Logger = logger_1.default;
9
- var constants_1 = require("./lib/constants");
10
- Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return constants_1.Level; } });
11
- Object.defineProperty(exports, "MiddlewareVerbosity", { enumerable: true, get: function () { return constants_1.MiddlewareVerbosity; } });
12
- exports.default = logger_1.default;
13
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAkC;AAIzB,iBAJF,gBAAM,CAIE;AAFf,6CAAyE;AAAhE,qGAAA,KAAK,OAAY;AAAE,gHAAA,mBAAmB,OAAA;AAI/C,kBAAe,gBAAM,CAAC"}
@@ -1,23 +0,0 @@
1
- /// <reference types="pino" />
2
- import { redactOptions } from '@voiceflow/pino';
3
- export declare enum Level {
4
- INFO = "info",
5
- WARN = "warn",
6
- TRACE = "trace",
7
- ERROR = "error",
8
- FATAL = "fatal"
9
- }
10
- export declare enum MiddlewareVerbosity {
11
- NONE = "none",
12
- FULL = "full",
13
- SHORT = "short",
14
- DEBUG = "debug"
15
- }
16
- export interface LoggerConfig {
17
- level?: Level | null;
18
- pretty?: boolean;
19
- redact?: string[] | redactOptions;
20
- withTraceID?: boolean;
21
- middlewareVerbosity?: MiddlewareVerbosity | null;
22
- }
23
- export declare const defaultConfigs: LoggerConfig;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultConfigs = exports.MiddlewareVerbosity = exports.Level = void 0;
4
- var Level;
5
- (function (Level) {
6
- Level["INFO"] = "info";
7
- Level["WARN"] = "warn";
8
- Level["TRACE"] = "trace";
9
- Level["ERROR"] = "error";
10
- Level["FATAL"] = "fatal";
11
- })(Level = exports.Level || (exports.Level = {}));
12
- var MiddlewareVerbosity;
13
- (function (MiddlewareVerbosity) {
14
- MiddlewareVerbosity["NONE"] = "none";
15
- MiddlewareVerbosity["FULL"] = "full";
16
- MiddlewareVerbosity["SHORT"] = "short";
17
- MiddlewareVerbosity["DEBUG"] = "debug";
18
- })(MiddlewareVerbosity = exports.MiddlewareVerbosity || (exports.MiddlewareVerbosity = {}));
19
- exports.defaultConfigs = {
20
- level: Level.INFO,
21
- pretty: false,
22
- withTraceID: true,
23
- middlewareVerbosity: MiddlewareVerbosity.SHORT,
24
- };
25
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../lib/constants.ts"],"names":[],"mappings":";;;AAEA,IAAY,KAMX;AAND,WAAY,KAAK;IACf,sBAAa,CAAA;IACb,sBAAa,CAAA;IACb,wBAAe,CAAA;IACf,wBAAe,CAAA;IACf,wBAAe,CAAA;AACjB,CAAC,EANW,KAAK,GAAL,aAAK,KAAL,aAAK,QAMhB;AAED,IAAY,mBAKX;AALD,WAAY,mBAAmB;IAC7B,oCAAa,CAAA;IACb,oCAAa,CAAA;IACb,sCAAe,CAAA;IACf,sCAAe,CAAA;AACjB,CAAC,EALW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAK9B;AAUY,QAAA,cAAc,GAAiB;IAC1C,KAAK,EAAE,KAAK,CAAC,IAAI;IACjB,MAAM,EAAE,KAAK;IACb,WAAW,EAAE,IAAI;IACjB,mBAAmB,EAAE,mBAAmB,CAAC,KAAK;CAC/C,CAAC"}
@@ -1,9 +0,0 @@
1
- import { Logger } from '@voiceflow/pino';
2
- import { HttpLogger } from 'pino-http';
3
- import { MiddlewareVerbosity } from './constants';
4
- declare const createMiddleware: ({ logger, genReqId, verbosity, }: {
5
- logger: Logger;
6
- genReqId?: (() => string) | undefined;
7
- verbosity?: MiddlewareVerbosity | null | undefined;
8
- }) => HttpLogger;
9
- export default createMiddleware;
@@ -1,51 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const pino_http_1 = __importDefault(require("pino-http"));
7
- const constants_1 = require("./constants");
8
- const utils_1 = require("./utils");
9
- const getSerializer = (verbosity) => {
10
- switch (verbosity) {
11
- case constants_1.MiddlewareVerbosity.NONE:
12
- return utils_1.noSerializer;
13
- case constants_1.MiddlewareVerbosity.SHORT:
14
- return utils_1.shortSerializer;
15
- case constants_1.MiddlewareVerbosity.FULL:
16
- return utils_1.fullSerializer;
17
- case constants_1.MiddlewareVerbosity.DEBUG:
18
- return utils_1.debugSerializer;
19
- default:
20
- return utils_1.fullSerializer;
21
- }
22
- };
23
- const createMiddleware = ({ logger, genReqId, verbosity, }) => pino_http_1.default({
24
- logger,
25
- genReqId,
26
- serializers: getSerializer(verbosity),
27
- customLogLevel(res, err) {
28
- if (res.statusCode >= 500 || err) {
29
- return constants_1.Level.ERROR;
30
- }
31
- if (res.statusCode >= 400) {
32
- if (res.statusCode === 404) {
33
- return constants_1.Level.TRACE;
34
- }
35
- return constants_1.Level.WARN;
36
- }
37
- return constants_1.Level.INFO;
38
- },
39
- customSuccessMessage(res) {
40
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
41
- // @ts-ignore
42
- const { baseUrl, path } = res.req;
43
- if (baseUrl || path) {
44
- return `${res.statusCode} | ${baseUrl !== null && baseUrl !== void 0 ? baseUrl : ''}${path !== null && path !== void 0 ? path : ''} `;
45
- }
46
- // This should never happen
47
- return `${res.statusCode} | (unknown path)`;
48
- },
49
- });
50
- exports.default = createMiddleware;
51
- //# sourceMappingURL=createMiddleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createMiddleware.js","sourceRoot":"","sources":["../../lib/createMiddleware.ts"],"names":[],"mappings":";;;;;AACA,0DAAoD;AAEpD,2CAAyD;AACzD,mCAAyF;AAEzF,MAAM,aAAa,GAAG,CAAC,SAAsC,EAAE,EAAE;IAC/D,QAAQ,SAAS,EAAE;QACjB,KAAK,+BAAmB,CAAC,IAAI;YAC3B,OAAO,oBAAY,CAAC;QACtB,KAAK,+BAAmB,CAAC,KAAK;YAC5B,OAAO,uBAAe,CAAC;QACzB,KAAK,+BAAmB,CAAC,IAAI;YAC3B,OAAO,sBAAc,CAAC;QACxB,KAAK,+BAAmB,CAAC,KAAK;YAC5B,OAAO,uBAAe,CAAC;QACzB;YACE,OAAO,sBAAc,CAAC;KACzB;AACH,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,EACxB,MAAM,EACN,QAAQ,EACR,SAAS,GAKV,EAAc,EAAE,CACf,mBAAW,CAAC;IACV,MAAM;IACN,QAAQ;IACR,WAAW,EAAE,aAAa,CAAC,SAAS,CAAC;IACrC,cAAc,CAAC,GAAG,EAAE,GAAG;QACrB,IAAI,GAAG,CAAC,UAAU,IAAI,GAAG,IAAI,GAAG,EAAE;YAChC,OAAO,iBAAK,CAAC,KAAK,CAAC;SACpB;QAED,IAAI,GAAG,CAAC,UAAU,IAAI,GAAG,EAAE;YACzB,IAAI,GAAG,CAAC,UAAU,KAAK,GAAG,EAAE;gBAC1B,OAAO,iBAAK,CAAC,KAAK,CAAC;aACpB;YAED,OAAO,iBAAK,CAAC,IAAI,CAAC;SACnB;QAED,OAAO,iBAAK,CAAC,IAAI,CAAC;IACpB,CAAC;IACD,oBAAoB,CAAC,GAAG;QACtB,6DAA6D;QAC7D,aAAa;QACb,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,GAAG,CAAC;QAElC,IAAI,OAAO,IAAI,IAAI,EAAE;YACnB,OAAO,GAAG,GAAG,CAAC,UAAU,MAAM,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,GAAG,CAAC;SAC7D;QAED,2BAA2B;QAC3B,OAAO,GAAG,GAAG,CAAC,UAAU,mBAAmB,CAAC;IAC9C,CAAC;CACF,CAAC,CAAC;AAEL,kBAAe,gBAAgB,CAAC"}
@@ -1,13 +0,0 @@
1
- import { Logger, LoggerOptions } from '@voiceflow/pino';
2
- import { HttpLogger } from 'pino-http';
3
- import { MiddlewareVerbosity } from './constants';
4
- declare const createTraced: ({ options, verbosity, traceIDLength, }: {
5
- options: LoggerOptions;
6
- verbosity?: MiddlewareVerbosity | null | undefined;
7
- traceIDLength?: number | undefined;
8
- namespaceName?: string | undefined;
9
- }) => {
10
- logger: Logger;
11
- middleware: HttpLogger;
12
- };
13
- export default createTraced;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const pino_1 = __importDefault(require("@voiceflow/pino"));
7
- const cls_hooked_1 = require("cls-hooked");
8
- const nanoid_1 = require("nanoid");
9
- const createMiddleware_1 = __importDefault(require("./createMiddleware"));
10
- const TRACED_DATA = 'traced-data';
11
- const DEFAULT_TRACE_LENGTH = 10;
12
- const namespace = cls_hooked_1.createNamespace('@voiceflow/logger');
13
- const createTraced = ({ options, verbosity, traceIDLength = DEFAULT_TRACE_LENGTH, }) => {
14
- const setTracedData = (data) => namespace.set(TRACED_DATA, data);
15
- const getTracedData = () => namespace.get(TRACED_DATA);
16
- const logger = pino_1.default(options);
17
- const proxifiedLogger = new Proxy(logger, {
18
- get: (target, property, receiver) => { var _a; return Reflect.get(((_a = getTracedData()) === null || _a === void 0 ? void 0 : _a.logger) || target, property, receiver); },
19
- has: (target, key) => { var _a; return Reflect.has(((_a = getTracedData()) === null || _a === void 0 ? void 0 : _a.logger) || target, key); },
20
- apply: (target, thisArg, args) => { var _a; return Reflect.apply((((_a = getTracedData()) === null || _a === void 0 ? void 0 : _a.logger) || target), thisArg, args); },
21
- ownKeys: (target) => { var _a; return Reflect.ownKeys(((_a = getTracedData()) === null || _a === void 0 ? void 0 : _a.logger) || target); },
22
- construct: (target, args) => { var _a; return Reflect.construct((((_a = getTracedData()) === null || _a === void 0 ? void 0 : _a.logger) || target), args); },
23
- getOwnPropertyDescriptor: (target, key) => { var _a; return Reflect.getOwnPropertyDescriptor(((_a = getTracedData()) === null || _a === void 0 ? void 0 : _a.logger) || target, key); },
24
- });
25
- const middleware = createMiddleware_1.default({
26
- logger: proxifiedLogger,
27
- verbosity,
28
- genReqId: () => { var _a, _b; return (_b = (_a = getTracedData()) === null || _a === void 0 ? void 0 : _a.traceID) !== null && _b !== void 0 ? _b : nanoid_1.nanoid(traceIDLength); },
29
- });
30
- const tracedMiddleware = (req, res, next) => {
31
- namespace.bindEmitter(req);
32
- namespace.bindEmitter(res);
33
- const traceID = nanoid_1.nanoid(traceIDLength);
34
- const tracedLogger = logger.child({ traceID });
35
- namespace.run(() => {
36
- setTracedData({ traceID, logger: tracedLogger });
37
- middleware(req, res, next);
38
- });
39
- };
40
- return {
41
- logger: proxifiedLogger,
42
- middleware: tracedMiddleware,
43
- };
44
- };
45
- exports.default = createTraced;
46
- //# sourceMappingURL=createTraced.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createTraced.js","sourceRoot":"","sources":["../../lib/createTraced.ts"],"names":[],"mappings":";;;;;AAAA,2DAA8D;AAC9D,2CAA6C;AAC7C,mCAAgC;AAIhC,0EAAkD;AAElD,MAAM,WAAW,GAAG,aAAa,CAAC;AAClC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC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SAAS,CAAC,CAAC,OAAA,aAAa,EAAE,0CAAE,MAAM,KAAI,MAAM,CAAQ,EAAE,IAAI,CAAC,CAAA,EAAA;QAChG,wBAAwB,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,WAAC,OAAA,OAAO,CAAC,wBAAwB,CAAC,OAAA,aAAa,EAAE,0CAAE,MAAM,KAAI,MAAM,EAAE,GAAG,CAAC,CAAA,EAAA;KACpH,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,0BAAgB,CAAC;QAClC,MAAM,EAAE,eAAe;QACvB,SAAS;QACT,QAAQ,EAAE,GAAG,EAAE,kCAAC,aAAa,EAAE,0CAAE,OAAO,mCAAI,eAAM,CAAC,aAAa,CAAC,GAAA;KAClE,CAAC,CAAC;IAEH,MAAM,gBAAgB,GAAe,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACtD,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAC3B,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAE3B,MAAM,OAAO,GAAG,eAAM,CAAC,aAAa,CAAC,CAAC;QACtC,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QAE/C,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE;YACjB,aAAa,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;YAEjD,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO;QACL,MAAM,EAAE,eAAe;QACvB,UAAU,EAAE,gBAAgB;KAC7B,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,YAAY,CAAC"}
@@ -1,24 +0,0 @@
1
- import { HttpLogger } from 'pino-http';
2
- import { LoggerConfig } from './constants';
3
- declare class Logger {
4
- private logger;
5
- private middleware;
6
- constructor(config?: LoggerConfig);
7
- trace(message: unknown): void;
8
- debug(message: unknown): void;
9
- info(message: unknown): void;
10
- warn(message: unknown): void;
11
- error(message: unknown): void;
12
- fatal(message: unknown): void;
13
- logMiddleware(): HttpLogger;
14
- /**
15
- * Format an object of variables into a string.
16
- *
17
- * @example
18
- * ```js
19
- * logger.vars({ a: 1, b: 2, c: 3 }); // '| a=1 b=2 c=3'
20
- * ```
21
- */
22
- vars(variables: Record<string, unknown>, prefix?: string): string;
23
- }
24
- export default Logger;
@@ -1,76 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const pino_1 = __importDefault(require("@voiceflow/pino"));
7
- const pino_pretty_1 = __importDefault(require("@voiceflow/pino-pretty"));
8
- const util_1 = __importDefault(require("util"));
9
- const __1 = require("..");
10
- const constants_1 = require("./constants");
11
- const createMiddleware_1 = __importDefault(require("./createMiddleware"));
12
- const createTraced_1 = __importDefault(require("./createTraced"));
13
- const utils_1 = require("./utils");
14
- class Logger {
15
- constructor(config = constants_1.defaultConfigs) {
16
- const cfg = Object.assign(constants_1.defaultConfigs, config);
17
- const options = {
18
- base: null,
19
- level: cfg.level || __1.LogLevel.ERROR,
20
- serializers: { err: utils_1.errorSerializer },
21
- };
22
- if (cfg === null || cfg === void 0 ? void 0 : cfg.pretty) {
23
- options.prettifier = pino_pretty_1.default;
24
- options.prettyPrint = { levelFirst: true, translateTime: true };
25
- }
26
- if (cfg.withTraceID) {
27
- const traced = createTraced_1.default({ options, verbosity: cfg.middlewareVerbosity });
28
- this.logger = traced.logger;
29
- this.middleware = traced.middleware;
30
- }
31
- else {
32
- this.logger = pino_1.default(options);
33
- this.middleware = createMiddleware_1.default({ logger: this.logger, verbosity: cfg.middlewareVerbosity });
34
- }
35
- }
36
- trace(message) {
37
- this.logger.trace(message);
38
- }
39
- debug(message) {
40
- this.logger.debug(message);
41
- }
42
- info(message) {
43
- this.logger.info(message);
44
- }
45
- warn(message) {
46
- this.logger.warn(message);
47
- }
48
- error(message) {
49
- this.logger.error(message);
50
- }
51
- fatal(message) {
52
- this.logger.fatal(message);
53
- }
54
- logMiddleware() {
55
- return this.middleware;
56
- }
57
- /**
58
- * Format an object of variables into a string.
59
- *
60
- * @example
61
- * ```js
62
- * logger.vars({ a: 1, b: 2, c: 3 }); // '| a=1 b=2 c=3'
63
- * ```
64
- */
65
- vars(variables, prefix = '| ') {
66
- return (prefix +
67
- Object.entries(variables)
68
- .map(([key, value]) => {
69
- const serializedValue = value !== null && typeof value === 'object' ? util_1.default.inspect(value) : value;
70
- return `${key}=${serializedValue}`;
71
- })
72
- .join(', '));
73
- }
74
- }
75
- exports.default = Logger;
76
- //# sourceMappingURL=logger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../lib/logger.ts"],"names":[],"mappings":";;;;;AAAA,2DAA4E;AAC5E,yEAAgD;AAEhD,gDAAwB;AAExB,0BAA8B;AAC9B,2CAA2D;AAC3D,0EAAkD;AAClD,kEAA0C;AAC1C,mCAA0C;AAE1C,MAAM,MAAM;IAKV,YAAY,SAAuB,0BAAc;QAC/C,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,0BAAc,EAAE,MAAM,CAAC,CAAC;QAElD,MAAM,OAAO,GAAkB;YAC7B,IAAI,EAAE,IAAI;YACV,KAAK,EAAE,GAAG,CAAC,KAAM,IAAI,YAAQ,CAAC,KAAK;YACnC,WAAW,EAAE,EAAE,GAAG,EAAE,uBAAe,EAAE;SACtC,CAAC;QAEF,IAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,EAAE;YACf,OAAO,CAAC,UAAU,GAAG,qBAAU,CAAC;YAChC,OAAO,CAAC,WAAW,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;SACjE;QAED,IAAI,GAA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tB,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;gBACpB,MAAM,eAAe,GAAG,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;gBAElG,OAAO,GAAG,GAAG,IAAI,eAAe,EAAE,CAAC;YACrC,CAAC,CAAC;iBACD,IAAI,CAAC,IAAI,CAAC,CACd,CAAC;IACJ,CAAC;CACF;AAED,kBAAe,MAAM,CAAC"}
@@ -1,37 +0,0 @@
1
- import { SerializedError, SerializedRequest, SerializedResponse } from '@voiceflow/pino';
2
- export declare const errorSerializer: (err: any) => SerializedError;
3
- export declare const noSerializer: {
4
- err: () => void;
5
- req: () => void;
6
- res: () => void;
7
- traceID: () => void;
8
- responseTime: () => void;
9
- };
10
- export declare const shortSerializer: {
11
- err: (err: any) => SerializedError;
12
- req: ({ url }: SerializedRequest) => {
13
- url: string;
14
- };
15
- res: ({ statusCode }: SerializedResponse) => number;
16
- responseTime: () => void;
17
- };
18
- export declare const fullSerializer: {
19
- err: (err: any) => SerializedError;
20
- req: typeof import("pino-std-serializers").req;
21
- res: typeof import("pino-std-serializers").res;
22
- };
23
- export declare const debugSerializer: {
24
- err: (err: any) => SerializedError;
25
- req(req: SerializedRequest & {
26
- body: unknown;
27
- raw: {
28
- body: unknown;
29
- };
30
- }): SerializedRequest;
31
- res(res: SerializedRequest & {
32
- body: unknown;
33
- raw: {
34
- body: unknown;
35
- };
36
- }): SerializedRequest;
37
- };
@@ -1,44 +0,0 @@
1
- "use strict";
2
- /* eslint-disable @typescript-eslint/no-empty-function */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.debugSerializer = exports.fullSerializer = exports.shortSerializer = exports.noSerializer = exports.errorSerializer = void 0;
5
- const pino_1 = require("@voiceflow/pino");
6
- exports.errorSerializer = (err) => {
7
- var _a, _b, _c;
8
- const lines = (_a = err.stack) === null || _a === void 0 ? void 0 : _a.split('\n').filter((str) => !str.match(/node_modules\/|\\|\\\\(pino|@voiceflow\/|\\|\\\\logger)/));
9
- err.stack = lines === null || lines === void 0 ? void 0 : lines.join('');
10
- if (err.isAxiosError) {
11
- return pino_1.stdSerializers.err((_c = (_b = err.toJSON) === null || _b === void 0 ? void 0 : _b.call(err)) !== null && _c !== void 0 ? _c : err);
12
- }
13
- return pino_1.stdSerializers.err(err);
14
- };
15
- exports.noSerializer = {
16
- err: () => { },
17
- req: () => { },
18
- res: () => { },
19
- traceID: () => { },
20
- responseTime: () => { },
21
- };
22
- exports.shortSerializer = {
23
- err: exports.errorSerializer,
24
- req: ({ url }) => ({ url }),
25
- res: ({ statusCode }) => statusCode,
26
- responseTime: () => { },
27
- };
28
- exports.fullSerializer = {
29
- err: exports.errorSerializer,
30
- req: pino_1.stdSerializers.req,
31
- res: pino_1.stdSerializers.res,
32
- };
33
- exports.debugSerializer = {
34
- err: exports.errorSerializer,
35
- req(req) {
36
- req.body = req.raw.body;
37
- return req;
38
- },
39
- res(res) {
40
- res.body = res.raw.body;
41
- return res;
42
- },
43
- };
44
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAEzD,0CAAyG;AAE5F,QAAA,eAAe,GAAG,CAAC,GAAQ,EAAmB,EAAE;;IAC3D,MAAM,KAAK,SAAG,GAAG,CAAC,KAAK,0CAAE,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC,CAAC;IAE5H,GAAG,CAAC,KAAK,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAE5B,IAAI,GAAG,CAAC,YAAY,EAAE;QACpB,OAA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