@voiceflow/logger 1.0.0 → 1.0.1

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 (46) hide show
  1. package/README.md +25 -1
  2. package/build/detailed.logger.d.ts +4 -0
  3. package/build/detailed.logger.js +17 -0
  4. package/build/detailed.logger.js.map +1 -0
  5. package/build/http.logger.d.ts +5 -0
  6. package/build/http.logger.js +33 -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 +20 -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 +16 -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/serializers/maximal.d.ts +24 -0
  30. package/build/serializers/maximal.js +25 -0
  31. package/build/serializers/maximal.js.map +1 -0
  32. package/build/serializers/minimal.d.ts +19 -0
  33. package/build/serializers/minimal.js +22 -0
  34. package/build/serializers/minimal.js.map +1 -0
  35. package/build/utils.d.ts +5 -0
  36. package/build/utils.js +17 -0
  37. package/build/utils.js.map +1 -0
  38. package/package.json +64 -61
  39. package/.eslintrc.js +0 -24
  40. package/commitlint.config.js +0 -5
  41. package/index.js +0 -5
  42. package/lib/logger/index.js +0 -5
  43. package/lib/logger/logger.js +0 -65
  44. package/lib/utils/caller.js +0 -26
  45. package/lib/utils/index.js +0 -7
  46. package/test.js +0 -5
package/README.md CHANGED
@@ -1,2 +1,26 @@
1
+ [![circle ci](https://circleci.com/gh/voiceflow/logger.svg?style=shield&circle-token=8c4e4ce8d04d87f16e903bd7e1ccab194a118262)](https://circleci.com/gh/voiceflow/logger)
2
+ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=voiceflow_logger&metric=coverage)](https://sonarcloud.io/dashboard?id=voiceflow_logger)
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
+
1
5
  # logger
2
- Logging package for unified logging features
6
+
7
+ A standardized package for logging built on `pino`.
8
+
9
+ ## Usage
10
+
11
+ ```ts
12
+ import { createLogger, LogLevel, LogFormat } from '@voiceflow/logger';
13
+
14
+ const logger = createLogger({ format: LogFormat.JSON, level: LogLevel.INFO });
15
+
16
+ const inlineLogger = createLogger({ format: LogFormat.INLINE, level: LogLevel.WARN });
17
+
18
+ const detailedLogger = createLogger({ format: LogFormat.DETAILED, level: LogLevel.TRACE });
19
+
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<never>;
@@ -0,0 +1,17 @@
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 maximal_1 = require("./serializers/maximal");
9
+ const createDetailedConfig = (level) => ({
10
+ level,
11
+ transport: { target: 'pino-pretty' },
12
+ serializers: maximal_1.MaximalSerializer,
13
+ });
14
+ exports.createDetailedConfig = createDetailedConfig;
15
+ const createDetailedLogger = (level) => (0, pino_1.default)((0, exports.createDetailedConfig)(level));
16
+ exports.createDetailedLogger = createDetailedLogger;
17
+ //# 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;AAGxB,mDAA0D;AAEnD,MAAM,oBAAoB,GAAG,CAAC,KAAe,EAAsB,EAAE,CAAC,CAAC;IAC5E,KAAK;IACL,SAAS,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE;IACpC,WAAW,EAAE,2BAAiB;CAC/B,CAAC,CAAC;AAJU,QAAA,oBAAoB,wBAI9B;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,5 @@
1
+ /// <reference types="node/http" />
2
+ import { Options } from 'pino-http';
3
+ import { LoggerOptions } from './logger-options.interface';
4
+ export declare const createHTTPConfig: ({ format, level }: LoggerOptions) => Options;
5
+ export declare const createHTTPLogger: (options: LoggerOptions) => import("pino-http").HttpLogger<import("http").IncomingMessage, import("http").ServerResponse, never>;
@@ -0,0 +1,33 @@
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
+ }, wrapSerializers: true }, (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}`)} ${(0, colorette_1.gray)(`(${req.socket.remoteAddress}:${req.socket.remotePort})`)}`, customErrorMessage: (req, res) => {
25
+ var _a;
26
+ return `${(0, utils_1.getColorizer)(res)(`(${res.statusCode})`)} ${(0, colorette_1.white)(`${req.method} ${req.url} -`)} ${(0, colorette_1.gray)(`(${req.socket.remoteAddress}:${req.socket.remotePort})`)} ${(_a = res.err) === null || _a === void 0 ? void 0 : _a.message}`;
27
+ } }, (0, inline_logger_1.createInlineConfig)(level))))
28
+ .with(log_format_enum_1.LogFormat.DETAILED, () => (0, detailed_logger_1.createDetailedConfig)(level))
29
+ .otherwise(() => (0, json_logger_1.createJSONConfig)(level))));
30
+ exports.createHTTPConfig = createHTTPConfig;
31
+ const createHTTPLogger = (options) => (0, pino_http_1.default)((0, exports.createHTTPConfig)(options));
32
+ exports.createHTTPLogger = createHTTPLogger;
33
+ //# 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,yCAAwC;AACxC,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,EACD,eAAe,EAAE,IAAI,IAElB,IAAA,kBAAK,EAAqB,MAAM,CAAC;KACjC,IAAI,CAAC,2BAAS,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,iBAC5B,oBAAoB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CACjC,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,IAAI,IAAA,gBAAI,EACtF,IAAI,GAAG,CAAC,MAAM,CAAC,aAAa,IAAI,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,CACzD,EAAE,EACL,kBAAkB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;;QAC/B,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,IAAA,gBAAI,EACxF,IAAI,GAAG,CAAC,MAAM,CAAC,aAAa,IAAI,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,CACzD,IAAI,MAAA,GAAG,CAAC,GAAG,0CAAE,OAAO,EAAE,CAAA;KAAA,IACtB,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;AAtBU,QAAA,gBAAgB,oBAsB1B;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<never>;
@@ -0,0 +1,20 @@
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 minimal_1 = require("./serializers/minimal");
9
+ const createInlineConfig = (level) => ({
10
+ level,
11
+ transport: {
12
+ target: 'pino-pretty',
13
+ options: { include: 'time,level' },
14
+ },
15
+ serializers: minimal_1.MinimalSerializer,
16
+ });
17
+ exports.createInlineConfig = createInlineConfig;
18
+ const createInlineLogger = (level) => (0, pino_1.default)((0, exports.createInlineConfig)(level));
19
+ exports.createInlineLogger = createInlineLogger;
20
+ //# 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;AAGxB,mDAA0D;AAEnD,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;IACD,WAAW,EAAE,2BAAiB;CAC/B,CAAC,CAAC;AAPU,QAAA,kBAAkB,sBAO5B;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<never>;
@@ -0,0 +1,16 @@
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 minimal_1 = require("./serializers/minimal");
9
+ const createJSONConfig = (level) => ({
10
+ level,
11
+ serializers: minimal_1.MinimalSerializer,
12
+ });
13
+ exports.createJSONConfig = createJSONConfig;
14
+ const createJSONLogger = (level) => (0, pino_1.default)((0, exports.createJSONConfig)(level));
15
+ exports.createJSONLogger = createJSONLogger;
16
+ //# 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;AAGxB,mDAA0D;AAEnD,MAAM,gBAAgB,GAAG,CAAC,KAAe,EAAsB,EAAE,CAAC,CAAC;IACxE,KAAK;IACL,WAAW,EAAE,2BAAiB;CAC/B,CAAC,CAAC;AAHU,QAAA,gBAAgB,oBAG1B;AAEI,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<never>;
@@ -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,24 @@
1
+ import { SerializedError, SerializedRequest, SerializedResponse } from 'pino';
2
+ export declare const MaximalSerializer: {
3
+ req: (req: SerializedRequest) => {
4
+ id: string | undefined;
5
+ method: string;
6
+ url: string;
7
+ query: Record<string, string>;
8
+ params: Record<string, string>;
9
+ headers: {
10
+ [k: string]: string;
11
+ };
12
+ remoteAddress: string;
13
+ remotePort: number;
14
+ };
15
+ res: (res: SerializedResponse) => {
16
+ statusCode: number;
17
+ headers: Record<string, string>;
18
+ };
19
+ err: (err: SerializedError) => {
20
+ type: string;
21
+ message: string;
22
+ stack: string;
23
+ };
24
+ };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MaximalSerializer = void 0;
4
+ exports.MaximalSerializer = {
5
+ req: (req) => ({
6
+ id: req.id,
7
+ method: req.method,
8
+ url: req.url,
9
+ query: req.query,
10
+ params: req.params,
11
+ headers: Object.fromEntries(Object.entries(req.headers).filter(([key]) => key === 'authorization')),
12
+ remoteAddress: req.remoteAddress,
13
+ remotePort: req.remotePort,
14
+ }),
15
+ res: (res) => ({
16
+ statusCode: res.statusCode,
17
+ headers: res.headers,
18
+ }),
19
+ err: (err) => ({
20
+ type: err.type,
21
+ message: err.message,
22
+ stack: err.stack,
23
+ }),
24
+ };
25
+ //# sourceMappingURL=maximal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maximal.js","sourceRoot":"","sources":["../../src/serializers/maximal.ts"],"names":[],"mappings":";;;AAEa,QAAA,iBAAiB,GAAG;IAC/B,GAAG,EAAE,CAAC,GAAsB,EAAE,EAAE,CAAC,CAAC;QAChC,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,eAAe,CAAC,CAAC;QACnG,aAAa,EAAE,GAAG,CAAC,aAAa;QAChC,UAAU,EAAE,GAAG,CAAC,UAAU;KAC3B,CAAC;IACF,GAAG,EAAE,CAAC,GAAuB,EAAE,EAAE,CAAC,CAAC;QACjC,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,OAAO,EAAE,GAAG,CAAC,OAAO;KACrB,CAAC;IACF,GAAG,EAAE,CAAC,GAAoB,EAAE,EAAE,CAAC,CAAC;QAC9B,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,KAAK,EAAE,GAAG,CAAC,KAAK;KACjB,CAAC;CACH,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { SerializedError, SerializedRequest, SerializedResponse } from 'pino';
2
+ export declare const MinimalSerializer: {
3
+ req: (req: SerializedRequest) => {
4
+ method: string;
5
+ url: string;
6
+ query: Record<string, string>;
7
+ params: Record<string, string>;
8
+ remoteAddress: string;
9
+ remotePort: number;
10
+ };
11
+ res: (res: SerializedResponse) => {
12
+ statusCode: number;
13
+ };
14
+ err: (err: SerializedError) => {
15
+ type: string;
16
+ message: string;
17
+ stack: string;
18
+ };
19
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MinimalSerializer = void 0;
4
+ exports.MinimalSerializer = {
5
+ req: (req) => ({
6
+ method: req.method,
7
+ url: req.url,
8
+ query: req.query,
9
+ params: req.params,
10
+ remoteAddress: req.remoteAddress,
11
+ remotePort: req.remotePort,
12
+ }),
13
+ res: (res) => ({
14
+ statusCode: res.statusCode,
15
+ }),
16
+ err: (err) => ({
17
+ type: err.type,
18
+ message: err.message,
19
+ stack: err.stack,
20
+ }),
21
+ };
22
+ //# sourceMappingURL=minimal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"minimal.js","sourceRoot":"","sources":["../../src/serializers/minimal.ts"],"names":[],"mappings":";;;AAEa,QAAA,iBAAiB,GAAG;IAC/B,GAAG,EAAE,CAAC,GAAsB,EAAE,EAAE,CAAC,CAAC;QAChC,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,aAAa,EAAE,GAAG,CAAC,aAAa;QAChC,UAAU,EAAE,GAAG,CAAC,UAAU;KAC3B,CAAC;IACF,GAAG,EAAE,CAAC,GAAuB,EAAE,EAAE,CAAC,CAAC;QACjC,UAAU,EAAE,GAAG,CAAC,UAAU;KAC3B,CAAC;IACF,GAAG,EAAE,CAAC,GAAoB,EAAE,EAAE,CAAC,CAAC;QAC9B,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,KAAK,EAAE,GAAG,CAAC,KAAK;KACjB,CAAC;CACH,CAAC"}
@@ -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,76 +1,79 @@
1
1
  {
2
2
  "name": "@voiceflow/logger",
3
3
  "description": "Common logger for Voiceflow backend microservices",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "author": "Frank Gu <frank@voiceflow.com>",
6
+ "bugs": {
7
+ "url": "https://github.com/voiceflow/logger/issues"
8
+ },
9
+ "config": {
10
+ "commitizen": {
11
+ "path": "./node_modules/cz-conventional-changelog"
12
+ }
13
+ },
6
14
  "dependencies": {
7
- "express-pino-logger": "^4.0.0",
8
- "pino": "^5.14.0"
15
+ "colorette": "2.0.19",
16
+ "lodash.merge": "4.6.2",
17
+ "pino": "8.17.2",
18
+ "pino-http": "8.6.1",
19
+ "pino-pretty": "9.4.1",
20
+ "ts-pattern": "^4.0.5"
9
21
  },
10
22
  "devDependencies": {
11
- "@commitlint/cli": "^8.0.0",
12
- "@commitlint/config-conventional": "^8.0.0",
13
- "@voiceflow/commitlint-config": "^1.0.1",
14
- "@voiceflow/eslint-config": "^2.0.4",
15
- "@voiceflow/git-branch-check": "^1.0.2",
16
- "@voiceflow/prettier-config": "^1.0.4",
17
- "chai": "^4.2.0",
18
- "chai-as-promised": "^7.1.1",
19
- "codacy-coverage": "^3.4.0",
20
- "commitizen": "^3.1.1",
21
- "cz-conventional-changelog": "2.1.0",
22
- "eslint": "^6.0.1",
23
- "fixpack": "^2.3.1",
24
- "husky": "^3.0.0",
25
- "jest": "^24.8.0",
26
- "lint-staged": "^9.2.0",
27
- "mocha": "^6.1.4",
28
- "nyc": "^14.1.1",
29
- "prettier": "^1.18.2",
30
- "prettier-eslint-cli": "^5.0.0",
31
- "prettier-stylelint": "^0.4.2",
32
- "pretty-quick": "^1.11.1",
33
- "semantic-release": "^15.13.18",
34
- "sinon": "^7.3.2"
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",
28
+ "@voiceflow/commitlint-config": "2.0.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",
39
+ "eslint-output": "^3.0.1",
40
+ "fixpack": "^4.0.0",
41
+ "husky": "8.0.1",
42
+ "istanbul": "^0.4.5",
43
+ "lint-staged": "13.0.3",
44
+ "mocha": "10.0.0",
45
+ "nyc": "^15.1.0",
46
+ "prettier": "2.7.1",
47
+ "ts-mocha": "10.0.0",
48
+ "tsc-alias": "1.7.0",
49
+ "typescript": "4.8.3"
35
50
  },
36
51
  "files": [
37
- "lib/**/*",
38
- "*.js"
52
+ "build/"
53
+ ],
54
+ "homepage": "https://github.com/voiceflow/logger#readme",
55
+ "keywords": [
56
+ "voiceflow"
39
57
  ],
40
- "husky": {
41
- "hooks": {
42
- "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
43
- "pre-commit": "lint-staged",
44
- "pre-push": "git-branch-check"
45
- }
46
- },
47
58
  "license": "ISC",
48
- "lint-staged": {
49
- "package.json": [
50
- "fixpack",
51
- "git add"
52
- ],
53
- "**/*.js": [
54
- "eslint --fix",
55
- "prettier-eslint --write",
56
- "git add"
57
- ]
58
- },
59
- "main": "index.js",
59
+ "main": "build/main.js",
60
60
  "prettier": "@voiceflow/prettier-config",
61
- "release": {
62
- "branch": "production"
63
- },
64
61
  "repository": "git@github.com:voiceflow/logger.git",
65
62
  "scripts": {
66
- "commit": "git-cz",
67
- "integration": "mocha --use_strict --exit \"tests/**/*.it.js\"",
68
- "lint": "eslint \"**/*.js\" --fix",
69
- "lint:quiet": "yarn lint -- --quiet",
70
- "prepare": "fixpack",
71
- "send-coverage": "cat ./coverage/lcov.info | codacy-coverage",
72
- "test": "nyc mocha --use_strict --exit \"tests/**/*.unit.js\" \"tests/**/*.it.js\"",
73
- "unit": "mocha --use_strict --exit \"tests/**/*.unit.js\"",
74
- "update": "yarn install"
75
- }
63
+ "build": "yarn clean && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
64
+ "clean": "rimraf build",
65
+ "commit": "cz",
66
+ "eslint-output": "eslint-output",
67
+ "lint": "eslint '**/*.{js,ts}'",
68
+ "lint:output": "yarn run eslint-output --quiet \"**/*.{js,ts}\"",
69
+ "lint:report": "yarn lint:output",
70
+ "tdd": "yarn test --watch",
71
+ "test": "yarn test:run",
72
+ "test:dependencies": "depcheck",
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"
76
79
  }
package/.eslintrc.js DELETED
@@ -1,24 +0,0 @@
1
- module.exports = {
2
- extends: '@voiceflow/eslint-config',
3
- rules: {
4
- 'no-continue': 'off',
5
- 'no-process-env': 'off',
6
- 'class-methods-use-this': 'off', // migrating away from classes anyways
7
- 'require-jsdoc': 'off', // not sure we want this
8
- quotes: ['error', 'single', 'avoid-escape'],
9
- 'valid-jsdoc': 'off',
10
- 'func-names': 'off',
11
- // disabled temporarily by setting as warnings
12
- 'eslint-comments/disable-enable-pair': 'warn',
13
- 'eslint-comments/no-unlimited-disable': 'warn',
14
- 'promise/always-return': 'warn',
15
- 'promise/param-names': 'warn',
16
- 'sonarjs/cognitive-complexity': 'warn',
17
- 'sonarjs/no-duplicate-string': 'warn',
18
- 'sonarjs/no-identical-functions': 'warn',
19
- 'sonarjs/no-useless-catch': 'warn',
20
- 'sonarjs/no-collapsible-if': 'warn',
21
- 'sonarjs/prefer-object-literal': 'warn',
22
- 'consistent-return': 'warn',
23
- },
24
- };
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- extends: ['@voiceflow/commitlint-config'],
5
- };
package/index.js DELETED
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- const Logger = require('./lib/logger');
4
-
5
- module.exports = Logger;
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- const Logger = require('./logger');
4
-
5
- module.exports = Logger;
@@ -1,65 +0,0 @@
1
- 'use strict';
2
-
3
- const pino = require('pino');
4
- const expressPino = require('express-pino-logger');
5
-
6
- const { Caller } = require('../utils');
7
- const Prettifier = require('../../../pino-pretty');
8
-
9
- const defaultConfigs = {
10
- level: 'info',
11
- stackTrace: true,
12
- pretty: true,
13
- };
14
-
15
- class Logger {
16
- constructor(config) {
17
- this.config = config != null ? config : defaultConfigs;
18
- this.baseLoggerConfig = {
19
- level: this.config.level || defaultConfigs.level,
20
- base: null,
21
- };
22
-
23
- if(this.config.pretty){
24
- this.baseLoggerConfig.prettifier = Prettifier;
25
- this.baseLoggerConfig.prettyPrint = {
26
- levelFirst: true,
27
- translateTime: true,
28
- };
29
- }
30
-
31
- this.baseLogger = pino(this.baseLoggerConfig);
32
- this.middlewareLogger = expressPino({
33
- logger: this.baseLogger, // Use the instantiated base logger
34
- });
35
- }
36
-
37
- trace(...params) {
38
- this.baseLogger.trace(...params);
39
- }
40
-
41
- debug(...params) {
42
- this.baseLogger.debug(...params);
43
- }
44
-
45
- info(...params) {
46
- this.baseLogger.info(...params);
47
- }
48
-
49
- warn(...params) {
50
- const logPayload = Caller.identify(params); // Full stack trace not needed for warnings
51
- this.baseLogger.warn(...logPayload);
52
- }
53
-
54
- error(...params) {
55
- const logPayload = Caller.identify(params, this.config.stackTrace);
56
- this.baseLogger.error(...logPayload);
57
- }
58
-
59
- fatal(...params) {
60
- const logPayload = Caller.identify(params, this.config.stackTrace);
61
- this.baseLogger.fatal(...logPayload);
62
- }
63
- }
64
-
65
- module.exports = Logger;
@@ -1,26 +0,0 @@
1
- 'use strict';
2
-
3
- const STACKTRACE_OFFSET = 2;
4
- const LINE_OFFSET = 7;
5
-
6
- class Caller {
7
- static identify(params, stackTrace = false) {
8
- const callStack = Error()
9
- .stack.split('\n')
10
- .slice(STACKTRACE_OFFSET);
11
- const callFunction = callStack.filter((s) => !s.includes('node_modules/pino') && !s.includes('node_modules\\pino'))[1].substr(LINE_OFFSET);
12
- const callerObj = {
13
- stack: stackTrace ? callStack : callFunction,
14
- };
15
-
16
- if (typeof params[0] === 'object') {
17
- params[0].stack = callerObj.stack;
18
- } else {
19
- params.unshift(callerObj);
20
- }
21
-
22
- return params;
23
- }
24
- }
25
-
26
- module.exports = Caller;
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- const Caller = require('./caller');
4
-
5
- module.exports = {
6
- Caller,
7
- };
package/test.js DELETED
@@ -1,5 +0,0 @@
1
- const logger = require('./');
2
-
3
- const instance = new logger();
4
-
5
- instance.warn("asfd");