@vidavidorra/bunyan-pretty-stream 3.0.17 → 4.0.0-beta.2

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 (51) hide show
  1. package/LICENSE.md +70 -70
  2. package/dist/bunyan/core-fields.d.ts +6 -0
  3. package/dist/bunyan/core-fields.js +16 -0
  4. package/dist/bunyan/from-json-string.d.ts +3 -0
  5. package/dist/bunyan/from-json-string.js +17 -0
  6. package/dist/bunyan/index.d.ts +4 -0
  7. package/dist/bunyan/index.js +4 -0
  8. package/dist/bunyan/is-record.d.ts +3 -0
  9. package/dist/bunyan/is-record.js +17 -0
  10. package/dist/bunyan/record.d.ts +16 -0
  11. package/dist/bunyan/record.js +2 -0
  12. package/dist/bunyan-pretty-stream.d.ts +11 -0
  13. package/dist/bunyan-pretty-stream.js +25 -0
  14. package/dist/formatter/extra.d.ts +11 -0
  15. package/dist/formatter/extra.js +33 -0
  16. package/dist/formatter/extras.d.ts +7 -0
  17. package/dist/formatter/extras.js +18 -0
  18. package/dist/formatter/formatter.d.ts +25 -0
  19. package/dist/formatter/formatter.js +116 -0
  20. package/dist/formatter/index.d.ts +1 -0
  21. package/dist/formatter/index.js +2 -0
  22. package/dist/formatter/time.d.ts +11 -0
  23. package/dist/formatter/time.js +68 -0
  24. package/dist/helpers/normalise-path.d.ts +2 -0
  25. package/dist/helpers/normalise-path.js +9 -0
  26. package/dist/index.d.ts +3 -0
  27. package/dist/index.js +2 -0
  28. package/dist/{src/logger.d.ts → logger.d.ts} +2 -2
  29. package/dist/logger.js +2 -0
  30. package/dist/options.d.ts +332 -0
  31. package/dist/options.js +109 -0
  32. package/dist/parser/extras.d.ts +13 -0
  33. package/dist/parser/extras.js +47 -0
  34. package/dist/parser/parser.d.ts +22 -0
  35. package/dist/parser/parser.js +53 -0
  36. package/package.json +192 -45
  37. package/dist/src/bunyan-pretty-stream.d.ts +0 -10
  38. package/dist/src/bunyan-pretty-stream.js +0 -32
  39. package/dist/src/bunyan-record.d.ts +0 -19
  40. package/dist/src/bunyan-record.js +0 -55
  41. package/dist/src/formatter/extras.d.ts +0 -34
  42. package/dist/src/formatter/extras.js +0 -94
  43. package/dist/src/formatter/formatter.d.ts +0 -34
  44. package/dist/src/formatter/formatter.js +0 -200
  45. package/dist/src/formatter/index.d.ts +0 -2
  46. package/dist/src/formatter/index.js +0 -5
  47. package/dist/src/index.d.ts +0 -3
  48. package/dist/src/index.js +0 -5
  49. package/dist/src/logger.js +0 -2
  50. package/dist/src/options.d.ts +0 -151
  51. package/dist/src/options.js +0 -68
@@ -1,200 +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.Formatter = void 0;
7
- const bunyan_record_1 = require("../bunyan-record");
8
- const options_1 = require("../options");
9
- const extras_1 = require("./extras");
10
- const bunyan_1 = __importDefault(require("bunyan"));
11
- const chalk_1 = __importDefault(require("chalk"));
12
- const is_1 = __importDefault(require("@sindresorhus/is"));
13
- const moment_1 = __importDefault(require("moment"));
14
- const path_1 = __importDefault(require("path"));
15
- const json_stringify_pretty_compact_1 = __importDefault(require("json-stringify-pretty-compact"));
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- function sanitise(obj) {
18
- Object.entries(obj).forEach(([key, value]) => {
19
- if (is_1.default.undefined(value)) {
20
- delete obj[key];
21
- }
22
- else if (is_1.default.object(value)) {
23
- sanitise(value);
24
- }
25
- });
26
- return obj;
27
- }
28
- class Formatter {
29
- constructor(options) {
30
- this._regex = {
31
- newLine: /\r\n|\r|\n/,
32
- whitespace: /\s/,
33
- };
34
- this._internalOptions = {
35
- timeFormat: {
36
- short: 'HH:mm:ss.SSS',
37
- long: 'YYYY-MM-DD[T]HH:mm:ss.SSS',
38
- },
39
- };
40
- const parsedOptions = options_1.schema.parse(options);
41
- parsedOptions.basePath = path_1.default.normalize(parsedOptions.basePath);
42
- this._options = parsedOptions;
43
- this._levels = {
44
- [bunyan_1.default.levelFromName.trace]: chalk_1.default.gray('TRACE'),
45
- [bunyan_1.default.levelFromName.debug]: chalk_1.default.blue('DEBUG'),
46
- [bunyan_1.default.levelFromName.info]: chalk_1.default.green(' INFO'),
47
- [bunyan_1.default.levelFromName.warn]: chalk_1.default.magenta(' WARN'),
48
- [bunyan_1.default.levelFromName.error]: chalk_1.default.red('ERROR'),
49
- [bunyan_1.default.levelFromName.fatal]: chalk_1.default.bgRed('FATAL'),
50
- };
51
- }
52
- parse(record) {
53
- const parsed = {
54
- version: record.v,
55
- level: record.level,
56
- name: record.name,
57
- hostname: record.hostname,
58
- pid: record.pid,
59
- time: (0, moment_1.default)(record.time),
60
- message: record.msg,
61
- source: record.src,
62
- extras: new extras_1.Extras(this._options.extras.maxLength),
63
- details: sanitise(record),
64
- };
65
- Object.keys(parsed.details).forEach((key) => {
66
- if ((0, bunyan_record_1.coreFields)().includes(key)) {
67
- delete parsed.details[key];
68
- }
69
- });
70
- if (!this._options.show.extras) {
71
- return parsed;
72
- }
73
- const leftOvers = is_1.default.undefined(this._options.extras.key)
74
- ? parsed.details
75
- : parsed.details[this._options.extras.key];
76
- if (!is_1.default.nonEmptyObject(leftOvers)) {
77
- return parsed;
78
- }
79
- Object.entries(leftOvers).forEach(([key, value]) => {
80
- if (parsed.extras.parseAndAdd(key, value)) {
81
- delete leftOvers[key];
82
- }
83
- });
84
- return parsed;
85
- }
86
- format(record) {
87
- const parsedRecord = this.parse(record);
88
- return [
89
- this.formatTime((0, moment_1.default)(parsedRecord.time)),
90
- this.formatLevel(parsedRecord.level),
91
- ':',
92
- this.formatName(parsedRecord.name),
93
- this.formatPid(parsedRecord.pid),
94
- this.formatHostname(parsedRecord.hostname),
95
- this.formatSource(parsedRecord.source),
96
- this.formatMessage(parsedRecord.message),
97
- this.formatExtras(parsedRecord.extras),
98
- this._options.newLineCharacter,
99
- this.formatDetails(parsedRecord.message, parsedRecord.details),
100
- ].join('');
101
- }
102
- formatTime(time) {
103
- if (!this._options.show.time) {
104
- return '';
105
- }
106
- let format = this._options.time.format;
107
- if (this._options.time.type === 'short') {
108
- format = this._internalOptions.timeFormat.short;
109
- }
110
- else if (this._options.time.type === 'long') {
111
- format = this._internalOptions.timeFormat.long;
112
- }
113
- if (!this._options.time.local) {
114
- time.utc();
115
- format = format.concat('[Z]');
116
- }
117
- return `[${time.format(format)}]`;
118
- }
119
- formatLevel(level) {
120
- const prefix = this._options.show.time ? ' ' : '';
121
- return `${prefix}${this._levels[level]}`;
122
- }
123
- formatName(name) {
124
- if (!this._options.show.name) {
125
- return '';
126
- }
127
- return ` ${name}`;
128
- }
129
- formatPid(pid) {
130
- if (!this._options.show.pid) {
131
- return '';
132
- }
133
- const prefix = this._options.show.name ? '/' : ' ';
134
- return `${prefix}${pid}`;
135
- }
136
- formatHostname(hostname) {
137
- if (!this._options.show.hostname) {
138
- return '';
139
- }
140
- return [
141
- ' ',
142
- this._options.show.name || this._options.show.pid ? 'on ' : '',
143
- hostname,
144
- ].join('');
145
- }
146
- formatSource(source) {
147
- if (!this._options.show.source || is_1.default.undefined(source)) {
148
- return '';
149
- }
150
- const file = path_1.default.relative(this._options.basePath, source.file);
151
- const formattedSource = [
152
- ` (${file}:${source.line}`,
153
- !is_1.default.undefined(source.func) ? ` in ${source.func}` : '',
154
- ')',
155
- ].join('');
156
- return chalk_1.default.green(formattedSource);
157
- }
158
- formatMessage(message) {
159
- if (!this.isSingleLine(message)) {
160
- return '';
161
- }
162
- return chalk_1.default.blue(` ${message}`);
163
- }
164
- formatExtras(extras) {
165
- const formattedExtras = extras.format();
166
- return formattedExtras.length === 0 ? '' : chalk_1.default.red(` ${formattedExtras}`);
167
- }
168
- formatDetails(message, details) {
169
- const formatted = [];
170
- if (!this.isSingleLine(message)) {
171
- formatted.push(chalk_1.default.blue(this.indent(message, true)));
172
- }
173
- formatted.push(...Object.entries(details).map(([key, value]) => chalk_1.default.cyan(this.indent(`${key}: ${(0, json_stringify_pretty_compact_1.default)(value, {
174
- indent: this._options.indent.json,
175
- maxLength: 80,
176
- })}`, true))));
177
- const separator = [
178
- this._options.newLineCharacter,
179
- this.indent('--', true),
180
- this._options.newLineCharacter,
181
- ].join('');
182
- const suffix = formatted.length > 0 ? this._options.newLineCharacter : '';
183
- return `${formatted.join(separator)}${suffix}`;
184
- }
185
- isSingleLine(string) {
186
- return !this._regex.newLine.test(string);
187
- }
188
- containsWhitespace(string) {
189
- return this._regex.whitespace.test(string);
190
- }
191
- indent(input, leading = false) {
192
- const indentation = ' '.repeat(this._options.indent.details);
193
- const prefix = leading ? indentation : '';
194
- const formatted = input
195
- .split(this._regex.newLine)
196
- .join(`${this._options.newLineCharacter}${indentation}`);
197
- return `${prefix}${formatted}`;
198
- }
199
- }
200
- exports.Formatter = Formatter;
@@ -1,2 +0,0 @@
1
- import { Formatter } from './formatter';
2
- export { Formatter };
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Formatter = void 0;
4
- const formatter_1 = require("./formatter");
5
- Object.defineProperty(exports, "Formatter", { enumerable: true, get: function () { return formatter_1.Formatter; } });
@@ -1,3 +0,0 @@
1
- import { Logger } from './logger';
2
- import { PrettyStream } from './bunyan-pretty-stream';
3
- export { PrettyStream, Logger };
package/dist/src/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PrettyStream = void 0;
4
- const bunyan_pretty_stream_1 = require("./bunyan-pretty-stream");
5
- Object.defineProperty(exports, "PrettyStream", { enumerable: true, get: function () { return bunyan_pretty_stream_1.PrettyStream; } });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,151 +0,0 @@
1
- import { z } from 'zod';
2
- declare const schema: z.ZodObject<{
3
- show: z.ZodDefault<z.ZodObject<{
4
- time: z.ZodDefault<z.ZodBoolean>;
5
- name: z.ZodDefault<z.ZodBoolean>;
6
- hostname: z.ZodDefault<z.ZodBoolean>;
7
- pid: z.ZodDefault<z.ZodBoolean>;
8
- source: z.ZodDefault<z.ZodBoolean>;
9
- extras: z.ZodDefault<z.ZodBoolean>;
10
- }, "strict", z.ZodTypeAny, {
11
- source: boolean;
12
- name: boolean;
13
- time: boolean;
14
- hostname: boolean;
15
- pid: boolean;
16
- extras: boolean;
17
- }, {
18
- source?: boolean | undefined;
19
- name?: boolean | undefined;
20
- time?: boolean | undefined;
21
- hostname?: boolean | undefined;
22
- pid?: boolean | undefined;
23
- extras?: boolean | undefined;
24
- }>>;
25
- extras: z.ZodDefault<z.ZodObject<{
26
- key: z.ZodOptional<z.ZodString>;
27
- maxLength: z.ZodDefault<z.ZodObject<{
28
- key: z.ZodDefault<z.ZodNumber>;
29
- value: z.ZodDefault<z.ZodNumber>;
30
- total: z.ZodDefault<z.ZodNumber>;
31
- }, "strict", z.ZodTypeAny, {
32
- key: number;
33
- total: number;
34
- value: number;
35
- }, {
36
- key?: number | undefined;
37
- total?: number | undefined;
38
- value?: number | undefined;
39
- }>>;
40
- }, "strict", z.ZodTypeAny, {
41
- key?: string | undefined;
42
- maxLength: {
43
- key: number;
44
- total: number;
45
- value: number;
46
- };
47
- }, {
48
- key?: string | undefined;
49
- maxLength?: {
50
- key?: number | undefined;
51
- total?: number | undefined;
52
- value?: number | undefined;
53
- } | undefined;
54
- }>>;
55
- indent: z.ZodDefault<z.ZodObject<{
56
- details: z.ZodDefault<z.ZodNumber>;
57
- json: z.ZodDefault<z.ZodNumber>;
58
- }, "strict", z.ZodTypeAny, {
59
- details: number;
60
- json: number;
61
- }, {
62
- details?: number | undefined;
63
- json?: number | undefined;
64
- }>>;
65
- basePath: z.ZodDefault<z.ZodString>;
66
- newLineCharacter: z.ZodDefault<z.ZodEnum<["\r", "\n", "\r\n"]>>;
67
- time: z.ZodDefault<z.ZodObject<{
68
- type: z.ZodDefault<z.ZodEnum<["short", "long", "format"]>>;
69
- /**
70
- * Display local time instead of UTC.
71
- */
72
- local: z.ZodDefault<z.ZodBoolean>;
73
- /**
74
- * Time format as specified by the `Moment.js` [format options](
75
- * https://momentjs.com/docs/#/displaying/format/).
76
- *
77
- * @note The time zone, `Z` or `ZZ`, should be omitted as `Z` is
78
- * automatically to the format if the time is UTC.
79
- * @note The `Z` display suffix for UTC times is automatically added to
80
- * the format and should be omitted.
81
- */
82
- format: z.ZodDefault<z.ZodString>;
83
- }, "strict", z.ZodTypeAny, {
84
- type: "long" | "short" | "format";
85
- format: string;
86
- local: boolean;
87
- }, {
88
- type?: "long" | "short" | "format" | undefined;
89
- format?: string | undefined;
90
- local?: boolean | undefined;
91
- }>>;
92
- }, "strict", z.ZodTypeAny, {
93
- show: {
94
- source: boolean;
95
- name: boolean;
96
- time: boolean;
97
- hostname: boolean;
98
- pid: boolean;
99
- extras: boolean;
100
- };
101
- time: {
102
- type: "long" | "short" | "format";
103
- format: string;
104
- local: boolean;
105
- };
106
- extras: {
107
- key?: string | undefined;
108
- maxLength: {
109
- key: number;
110
- total: number;
111
- value: number;
112
- };
113
- };
114
- indent: {
115
- details: number;
116
- json: number;
117
- };
118
- basePath: string;
119
- newLineCharacter: "\r" | "\n" | "\r\n";
120
- }, {
121
- show?: {
122
- source?: boolean | undefined;
123
- name?: boolean | undefined;
124
- time?: boolean | undefined;
125
- hostname?: boolean | undefined;
126
- pid?: boolean | undefined;
127
- extras?: boolean | undefined;
128
- } | undefined;
129
- time?: {
130
- type?: "long" | "short" | "format" | undefined;
131
- format?: string | undefined;
132
- local?: boolean | undefined;
133
- } | undefined;
134
- extras?: {
135
- key?: string | undefined;
136
- maxLength?: {
137
- key?: number | undefined;
138
- total?: number | undefined;
139
- value?: number | undefined;
140
- } | undefined;
141
- } | undefined;
142
- indent?: {
143
- details?: number | undefined;
144
- json?: number | undefined;
145
- } | undefined;
146
- basePath?: string | undefined;
147
- newLineCharacter?: "\r" | "\n" | "\r\n" | undefined;
148
- }>;
149
- type Options = z.input<typeof schema>;
150
- type ParsedOptions = z.infer<typeof schema>;
151
- export { Options, ParsedOptions, schema };
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.schema = void 0;
4
- const bunyan_record_1 = require("./bunyan-record");
5
- const zod_1 = require("zod");
6
- const schema = zod_1.z
7
- .object({
8
- show: zod_1.z
9
- .object({
10
- time: zod_1.z.boolean().default(true),
11
- name: zod_1.z.boolean().default(false),
12
- hostname: zod_1.z.boolean().default(false),
13
- pid: zod_1.z.boolean().default(false),
14
- source: zod_1.z.boolean().default(false),
15
- extras: zod_1.z.boolean().default(true),
16
- })
17
- .strict()
18
- .default({}),
19
- extras: zod_1.z
20
- .object({
21
- key: zod_1.z
22
- .string()
23
- .min(1)
24
- .regex(new RegExp(`^((?!(${(0, bunyan_record_1.coreFields)().join('|')})).)*$`))
25
- .optional(),
26
- maxLength: zod_1.z
27
- .object({
28
- key: zod_1.z.number().int().positive().default(20),
29
- value: zod_1.z.number().int().positive().default(50),
30
- total: zod_1.z.number().int().positive().default(500),
31
- })
32
- .strict()
33
- .default({}),
34
- })
35
- .strict()
36
- .default({}),
37
- indent: zod_1.z
38
- .object({
39
- details: zod_1.z.number().int().nonnegative().default(4),
40
- json: zod_1.z.number().int().nonnegative().default(2),
41
- })
42
- .strict()
43
- .default({}),
44
- basePath: zod_1.z.string().min(1).default('/'),
45
- newLineCharacter: zod_1.z.enum(['\r', '\n', '\r\n']).default('\n'),
46
- time: zod_1.z
47
- .object({
48
- type: zod_1.z.enum(['short', 'long', 'format']).default('long'),
49
- /**
50
- * Display local time instead of UTC.
51
- */
52
- local: zod_1.z.boolean().default(false),
53
- /**
54
- * Time format as specified by the `Moment.js` [format options](
55
- * https://momentjs.com/docs/#/displaying/format/).
56
- *
57
- * @note The time zone, `Z` or `ZZ`, should be omitted as `Z` is
58
- * automatically to the format if the time is UTC.
59
- * @note The `Z` display suffix for UTC times is automatically added to
60
- * the format and should be omitted.
61
- */
62
- format: zod_1.z.string().min(1).default('YYYY-MM-DD[T]HH:mm:ss.SSS'),
63
- })
64
- .strict()
65
- .default({}),
66
- })
67
- .strict();
68
- exports.schema = schema;