tailwind-widgets 5.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +24 -0
- package/README.md +113 -0
- package/bin.js +6 -0
- package/bingo-logger.js +211 -0
- package/browser.js +358 -0
- package/docs/api.md +1352 -0
- package/docs/asynchronous.md +102 -0
- package/docs/benchmarks.md +58 -0
- package/docs/browser.md +199 -0
- package/docs/bundling.md +34 -0
- package/docs/child-loggers.md +95 -0
- package/docs/ecosystem.md +74 -0
- package/docs/help.md +305 -0
- package/docs/lts.md +62 -0
- package/docs/pretty.md +101 -0
- package/docs/redaction.md +135 -0
- package/docs/transports.md +792 -0
- package/docs/web.md +257 -0
- package/file.js +12 -0
- package/lib/caller.js +30 -0
- package/lib/deprecations.js +10 -0
- package/lib/levels.js +193 -0
- package/lib/meta.js +5 -0
- package/lib/multistream.js +156 -0
- package/lib/parse.js +14 -0
- package/lib/proto.js +216 -0
- package/lib/redaction.js +118 -0
- package/lib/symbols.js +70 -0
- package/lib/time.js +11 -0
- package/lib/tools.js +563 -0
- package/lib/transport-stream.js +47 -0
- package/lib/transport.js +157 -0
- package/lib/worker-pipeline.js +40 -0
- package/lib/worker.js +54 -0
- package/package.json +131 -0
- package/test/basic.test.js +719 -0
- package/test/broken-pipe.test.js +42 -0
- package/test/browser-levels.test.js +218 -0
- package/test/browser-serializers.test.js +354 -0
- package/test/browser-timestamp.test.js +88 -0
- package/test/browser-transmit.test.js +349 -0
- package/test/browser.test.js +547 -0
- package/test/complex-objects.test.js +34 -0
- package/test/crlf.test.js +32 -0
- package/test/custom-levels.test.js +294 -0
- package/test/error.test.js +374 -0
- package/test/escaping.test.js +91 -0
- package/test/esm/esm.mjs +12 -0
- package/test/esm/index.test.js +34 -0
- package/test/esm/named-exports.mjs +28 -0
- package/test/exit.test.js +85 -0
- package/test/final.test.js +237 -0
- package/test/fixtures/broken-pipe/basic.js +9 -0
- package/test/fixtures/broken-pipe/destination.js +10 -0
- package/test/fixtures/broken-pipe/syncfalse.js +12 -0
- package/test/fixtures/console-transport.js +13 -0
- package/test/fixtures/default-exit.js +8 -0
- package/test/fixtures/destination-exit.js +8 -0
- package/test/fixtures/eval/index.js +29 -0
- package/test/fixtures/eval/node_modules/14-files.js +3 -0
- package/test/fixtures/eval/node_modules/2-files.js +3 -0
- package/test/fixtures/eval/node_modules/file1.js +5 -0
- package/test/fixtures/eval/node_modules/file10.js +5 -0
- package/test/fixtures/eval/node_modules/file11.js +5 -0
- package/test/fixtures/eval/node_modules/file12.js +5 -0
- package/test/fixtures/eval/node_modules/file13.js +5 -0
- package/test/fixtures/eval/node_modules/file14.js +11 -0
- package/test/fixtures/eval/node_modules/file15.js +10 -0
- package/test/fixtures/eval/node_modules/file2.js +5 -0
- package/test/fixtures/eval/node_modules/file3.js +5 -0
- package/test/fixtures/eval/node_modules/file4.js +5 -0
- package/test/fixtures/eval/node_modules/file5.js +5 -0
- package/test/fixtures/eval/node_modules/file6.js +5 -0
- package/test/fixtures/eval/node_modules/file7.js +5 -0
- package/test/fixtures/eval/node_modules/file8.js +5 -0
- package/test/fixtures/eval/node_modules/file9.js +5 -0
- package/test/fixtures/eval/node_modules/test.list +3 -0
- package/test/fixtures/pretty/basic.js +6 -0
- package/test/fixtures/pretty/child-with-serializer.js +17 -0
- package/test/fixtures/pretty/child-with-updated-chindings.js +8 -0
- package/test/fixtures/pretty/child.js +8 -0
- package/test/fixtures/pretty/custom-time-label.js +9 -0
- package/test/fixtures/pretty/custom-time.js +9 -0
- package/test/fixtures/pretty/dateformat.js +10 -0
- package/test/fixtures/pretty/error-props.js +9 -0
- package/test/fixtures/pretty/error.js +7 -0
- package/test/fixtures/pretty/final-no-log-before.js +8 -0
- package/test/fixtures/pretty/final-return.js +7 -0
- package/test/fixtures/pretty/final.js +9 -0
- package/test/fixtures/pretty/formatters.js +13 -0
- package/test/fixtures/pretty/level-first.js +6 -0
- package/test/fixtures/pretty/no-time.js +9 -0
- package/test/fixtures/pretty/null-prototype.js +8 -0
- package/test/fixtures/pretty/obj-msg-prop.js +6 -0
- package/test/fixtures/pretty/pretty-factory.js +6 -0
- package/test/fixtures/pretty/redact.js +9 -0
- package/test/fixtures/pretty/serializers.js +17 -0
- package/test/fixtures/pretty/skipped-output.js +13 -0
- package/test/fixtures/pretty/suppress-flush-sync-warning.js +7 -0
- package/test/fixtures/stdout-hack-protection.js +11 -0
- package/test/fixtures/syncfalse-child.js +6 -0
- package/test/fixtures/syncfalse-exit.js +9 -0
- package/test/fixtures/syncfalse-flush-exit.js +10 -0
- package/test/fixtures/syncfalse.js +6 -0
- package/test/fixtures/to-file-transport-with-transform.js +20 -0
- package/test/fixtures/to-file-transport.js +13 -0
- package/test/fixtures/to-file-transport.mjs +8 -0
- package/test/fixtures/transport/index.js +12 -0
- package/test/fixtures/transport/package.json +5 -0
- package/test/fixtures/transport-exit-immediately-with-async-dest.js +16 -0
- package/test/fixtures/transport-exit-immediately.js +11 -0
- package/test/fixtures/transport-exit-on-ready.js +12 -0
- package/test/fixtures/transport-main.js +9 -0
- package/test/fixtures/transport-many-lines.js +29 -0
- package/test/fixtures/transport-string-stdout.js +9 -0
- package/test/fixtures/transport-transform.js +21 -0
- package/test/fixtures/transport-worker.js +13 -0
- package/test/fixtures/transport-wrong-export-type.js +3 -0
- package/test/fixtures/ts/to-file-transport-with-transform.ts +18 -0
- package/test/fixtures/ts/to-file-transport.es2017.cjs +12 -0
- package/test/fixtures/ts/to-file-transport.es5.cjs +58 -0
- package/test/fixtures/ts/to-file-transport.es6.cjs +23 -0
- package/test/fixtures/ts/to-file-transport.esnext.cjs +12 -0
- package/test/fixtures/ts/to-file-transport.ts +11 -0
- package/test/fixtures/ts/transpile.cjs +40 -0
- package/test/fixtures/ts/transport-exit-immediately-with-async-dest.ts +15 -0
- package/test/fixtures/ts/transport-exit-immediately.ts +10 -0
- package/test/fixtures/ts/transport-exit-on-ready.ts +11 -0
- package/test/fixtures/ts/transport-main.ts +8 -0
- package/test/fixtures/ts/transport-string-stdout.ts +8 -0
- package/test/fixtures/ts/transport-worker.ts +14 -0
- package/test/formatters.test.js +355 -0
- package/test/helper.d.ts +4 -0
- package/test/helper.js +128 -0
- package/test/hooks.test.js +97 -0
- package/test/http.test.js +242 -0
- package/test/is-level-enabled.test.js +43 -0
- package/test/jest/basic.spec.js +10 -0
- package/test/levels.test.js +528 -0
- package/test/metadata.test.js +106 -0
- package/test/mixin-merge-strategy.test.js +55 -0
- package/test/mixin.test.js +162 -0
- package/test/multistream.test.js +589 -0
- package/test/pretty.test.js +392 -0
- package/test/redact.test.js +828 -0
- package/test/serializers.test.js +253 -0
- package/test/stdout-protection.test.js +19 -0
- package/test/syncfalse.test.js +118 -0
- package/test/timestamp.test.js +121 -0
- package/test/transport/big.test.js +41 -0
- package/test/transport/bundlers-support.test.js +97 -0
- package/test/transport/caller.test.js +23 -0
- package/test/transport/core.test.js +546 -0
- package/test/transport/core.test.ts +236 -0
- package/test/transport/core.transpiled.test.ts +116 -0
- package/test/transport/module-link.test.js +239 -0
- package/test/transport/pipeline.test.js +36 -0
- package/test/transport/syncfalse.test.js +31 -0
- package/test/transport/targets.test.js +28 -0
- package/test/types/pino-import.test-d.ts +29 -0
- package/test/types/pino-multistream.test-d.ts +26 -0
- package/test/types/pino-top-export.test-d.ts +37 -0
- package/test/types/pino-transport.test-d.ts +122 -0
- package/test/types/pino-type-only.test-d.ts +16 -0
- package/test/types/pino.test-d.ts +341 -0
- package/test/types/pino.ts +42 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const { test } = require('tap')
|
|
3
|
+
const { sink, once } = require('./helper')
|
|
4
|
+
const stdSerializers = require('bingo-logger-std-serializers')
|
|
5
|
+
const bingo-logger = require('../')
|
|
6
|
+
|
|
7
|
+
const parentSerializers = {
|
|
8
|
+
test: () => 'parent'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const childSerializers = {
|
|
12
|
+
test: () => 'child'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
test('default err namespace error serializer', async ({ equal }) => {
|
|
16
|
+
const stream = sink()
|
|
17
|
+
const parent = bingo-logger(stream)
|
|
18
|
+
|
|
19
|
+
parent.info({ err: ReferenceError('test') })
|
|
20
|
+
const o = await once(stream, 'data')
|
|
21
|
+
equal(typeof o.err, 'object')
|
|
22
|
+
equal(o.err.type, 'ReferenceError')
|
|
23
|
+
equal(o.err.message, 'test')
|
|
24
|
+
equal(typeof o.err.stack, 'string')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('custom serializer overrides default err namespace error serializer', async ({ equal }) => {
|
|
28
|
+
const stream = sink()
|
|
29
|
+
const parent = bingo-logger({
|
|
30
|
+
serializers: {
|
|
31
|
+
err: (e) => ({
|
|
32
|
+
t: e.constructor.name,
|
|
33
|
+
m: e.message,
|
|
34
|
+
s: e.stack
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
}, stream)
|
|
38
|
+
|
|
39
|
+
parent.info({ err: ReferenceError('test') })
|
|
40
|
+
const o = await once(stream, 'data')
|
|
41
|
+
equal(typeof o.err, 'object')
|
|
42
|
+
equal(o.err.t, 'ReferenceError')
|
|
43
|
+
equal(o.err.m, 'test')
|
|
44
|
+
equal(typeof o.err.s, 'string')
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('custom serializer overrides default err namespace error serializer when nestedKey is on', async ({ equal }) => {
|
|
48
|
+
const stream = sink()
|
|
49
|
+
const parent = bingo-logger({
|
|
50
|
+
nestedKey: 'obj',
|
|
51
|
+
serializers: {
|
|
52
|
+
err: (e) => {
|
|
53
|
+
return {
|
|
54
|
+
t: e.constructor.name,
|
|
55
|
+
m: e.message,
|
|
56
|
+
s: e.stack
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}, stream)
|
|
61
|
+
|
|
62
|
+
parent.info({ err: ReferenceError('test') })
|
|
63
|
+
const o = await once(stream, 'data')
|
|
64
|
+
equal(typeof o.obj.err, 'object')
|
|
65
|
+
equal(o.obj.err.t, 'ReferenceError')
|
|
66
|
+
equal(o.obj.err.m, 'test')
|
|
67
|
+
equal(typeof o.obj.err.s, 'string')
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('null overrides default err namespace error serializer', async ({ equal }) => {
|
|
71
|
+
const stream = sink()
|
|
72
|
+
const parent = bingo-logger({ serializers: { err: null } }, stream)
|
|
73
|
+
|
|
74
|
+
parent.info({ err: ReferenceError('test') })
|
|
75
|
+
const o = await once(stream, 'data')
|
|
76
|
+
equal(typeof o.err, 'object')
|
|
77
|
+
equal(typeof o.err.type, 'undefined')
|
|
78
|
+
equal(typeof o.err.message, 'undefined')
|
|
79
|
+
equal(typeof o.err.stack, 'undefined')
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test('undefined overrides default err namespace error serializer', async ({ equal }) => {
|
|
83
|
+
const stream = sink()
|
|
84
|
+
const parent = bingo-logger({ serializers: { err: undefined } }, stream)
|
|
85
|
+
|
|
86
|
+
parent.info({ err: ReferenceError('test') })
|
|
87
|
+
const o = await once(stream, 'data')
|
|
88
|
+
equal(typeof o.err, 'object')
|
|
89
|
+
equal(typeof o.err.type, 'undefined')
|
|
90
|
+
equal(typeof o.err.message, 'undefined')
|
|
91
|
+
equal(typeof o.err.stack, 'undefined')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('serializers override values', async ({ equal }) => {
|
|
95
|
+
const stream = sink()
|
|
96
|
+
const parent = bingo-logger({ serializers: parentSerializers }, stream)
|
|
97
|
+
parent.child({}, { serializers: childSerializers })
|
|
98
|
+
|
|
99
|
+
parent.fatal({ test: 'test' })
|
|
100
|
+
const o = await once(stream, 'data')
|
|
101
|
+
equal(o.test, 'parent')
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test('child does not overwrite parent serializers', async ({ equal }) => {
|
|
105
|
+
const stream = sink()
|
|
106
|
+
const parent = bingo-logger({ serializers: parentSerializers }, stream)
|
|
107
|
+
const child = parent.child({}, { serializers: childSerializers })
|
|
108
|
+
|
|
109
|
+
parent.fatal({ test: 'test' })
|
|
110
|
+
|
|
111
|
+
const o = once(stream, 'data')
|
|
112
|
+
equal((await o).test, 'parent')
|
|
113
|
+
const o2 = once(stream, 'data')
|
|
114
|
+
child.fatal({ test: 'test' })
|
|
115
|
+
equal((await o2).test, 'child')
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
test('Symbol.for(\'bingo-logger.serializers\')', async ({ equal, same, not }) => {
|
|
119
|
+
const stream = sink()
|
|
120
|
+
const expected = Object.assign({
|
|
121
|
+
err: stdSerializers.err
|
|
122
|
+
}, parentSerializers)
|
|
123
|
+
const parent = bingo-logger({ serializers: parentSerializers }, stream)
|
|
124
|
+
const child = parent.child({ a: 'property' })
|
|
125
|
+
|
|
126
|
+
same(parent[Symbol.for('bingo-logger.serializers')], expected)
|
|
127
|
+
same(child[Symbol.for('bingo-logger.serializers')], expected)
|
|
128
|
+
equal(parent[Symbol.for('bingo-logger.serializers')], child[Symbol.for('bingo-logger.serializers')])
|
|
129
|
+
|
|
130
|
+
const child2 = parent.child({}, {
|
|
131
|
+
serializers: {
|
|
132
|
+
a
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
function a () {
|
|
137
|
+
return 'hello'
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
not(child2[Symbol.for('bingo-logger.serializers')], parentSerializers)
|
|
141
|
+
equal(child2[Symbol.for('bingo-logger.serializers')].a, a)
|
|
142
|
+
equal(child2[Symbol.for('bingo-logger.serializers')].test, parentSerializers.test)
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
test('children inherit parent serializers', async ({ equal }) => {
|
|
146
|
+
const stream = sink()
|
|
147
|
+
const parent = bingo-logger({ serializers: parentSerializers }, stream)
|
|
148
|
+
|
|
149
|
+
const child = parent.child({ a: 'property' })
|
|
150
|
+
child.fatal({ test: 'test' })
|
|
151
|
+
const o = await once(stream, 'data')
|
|
152
|
+
equal(o.test, 'parent')
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
test('children inherit parent Symbol serializers', async ({ equal, same, not }) => {
|
|
156
|
+
const stream = sink()
|
|
157
|
+
const symbolSerializers = {
|
|
158
|
+
[Symbol.for('b')]: b
|
|
159
|
+
}
|
|
160
|
+
const expected = Object.assign({
|
|
161
|
+
err: stdSerializers.err
|
|
162
|
+
}, symbolSerializers)
|
|
163
|
+
const parent = bingo-logger({ serializers: symbolSerializers }, stream)
|
|
164
|
+
|
|
165
|
+
same(parent[Symbol.for('bingo-logger.serializers')], expected)
|
|
166
|
+
|
|
167
|
+
const child = parent.child({}, {
|
|
168
|
+
serializers: {
|
|
169
|
+
[Symbol.for('a')]: a,
|
|
170
|
+
a
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
function a () {
|
|
175
|
+
return 'hello'
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function b () {
|
|
179
|
+
return 'world'
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
same(child[Symbol.for('bingo-logger.serializers')].a, a)
|
|
183
|
+
same(child[Symbol.for('bingo-logger.serializers')][Symbol.for('b')], b)
|
|
184
|
+
same(child[Symbol.for('bingo-logger.serializers')][Symbol.for('a')], a)
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
test('children serializers get called', async ({ equal }) => {
|
|
188
|
+
const stream = sink()
|
|
189
|
+
const parent = bingo-logger({
|
|
190
|
+
test: 'this'
|
|
191
|
+
}, stream)
|
|
192
|
+
|
|
193
|
+
const child = parent.child({ a: 'property' }, { serializers: childSerializers })
|
|
194
|
+
|
|
195
|
+
child.fatal({ test: 'test' })
|
|
196
|
+
const o = await once(stream, 'data')
|
|
197
|
+
equal(o.test, 'child')
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
test('children serializers get called when inherited from parent', async ({ equal }) => {
|
|
201
|
+
const stream = sink()
|
|
202
|
+
const parent = bingo-logger({
|
|
203
|
+
test: 'this',
|
|
204
|
+
serializers: parentSerializers
|
|
205
|
+
}, stream)
|
|
206
|
+
|
|
207
|
+
const child = parent.child({}, { serializers: { test: function () { return 'pass' } } })
|
|
208
|
+
|
|
209
|
+
child.fatal({ test: 'fail' })
|
|
210
|
+
const o = await once(stream, 'data')
|
|
211
|
+
equal(o.test, 'pass')
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
test('non-overridden serializers are available in the children', async ({ equal }) => {
|
|
215
|
+
const stream = sink()
|
|
216
|
+
const pSerializers = {
|
|
217
|
+
onlyParent: function () { return 'parent' },
|
|
218
|
+
shared: function () { return 'parent' }
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const cSerializers = {
|
|
222
|
+
shared: function () { return 'child' },
|
|
223
|
+
onlyChild: function () { return 'child' }
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const parent = bingo-logger({ serializers: pSerializers }, stream)
|
|
227
|
+
|
|
228
|
+
const child = parent.child({}, { serializers: cSerializers })
|
|
229
|
+
|
|
230
|
+
const o = once(stream, 'data')
|
|
231
|
+
child.fatal({ shared: 'test' })
|
|
232
|
+
equal((await o).shared, 'child')
|
|
233
|
+
const o2 = once(stream, 'data')
|
|
234
|
+
child.fatal({ onlyParent: 'test' })
|
|
235
|
+
equal((await o2).onlyParent, 'parent')
|
|
236
|
+
const o3 = once(stream, 'data')
|
|
237
|
+
child.fatal({ onlyChild: 'test' })
|
|
238
|
+
equal((await o3).onlyChild, 'child')
|
|
239
|
+
const o4 = once(stream, 'data')
|
|
240
|
+
parent.fatal({ onlyChild: 'test' })
|
|
241
|
+
equal((await o4).onlyChild, 'test')
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
test('custom serializer for messageKey', async (t) => {
|
|
245
|
+
const stream = sink()
|
|
246
|
+
const instance = bingo-logger({ serializers: { msg: () => '422' } }, stream)
|
|
247
|
+
|
|
248
|
+
const o = { num: NaN }
|
|
249
|
+
instance.info(o, 42)
|
|
250
|
+
|
|
251
|
+
const { msg } = await once(stream, 'data')
|
|
252
|
+
t.equal(msg, '422')
|
|
253
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('tap')
|
|
4
|
+
const { join } = require('path')
|
|
5
|
+
const { fork } = require('child_process')
|
|
6
|
+
const { once } = require('./helper')
|
|
7
|
+
const writer = require('flush-write-stream')
|
|
8
|
+
|
|
9
|
+
test('do not use SonicBoom is someone tampered with process.stdout.write', async ({ not }) => {
|
|
10
|
+
let actual = ''
|
|
11
|
+
const child = fork(join(__dirname, 'fixtures', 'stdout-hack-protection.js'), { silent: true })
|
|
12
|
+
|
|
13
|
+
child.stdout.pipe(writer((s, enc, cb) => {
|
|
14
|
+
actual += s
|
|
15
|
+
cb()
|
|
16
|
+
}))
|
|
17
|
+
await once(child, 'close')
|
|
18
|
+
not(actual.match(/^hack/), null)
|
|
19
|
+
})
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const os = require('os')
|
|
4
|
+
const { createWriteStream } = require('fs')
|
|
5
|
+
const { join } = require('path')
|
|
6
|
+
const { test } = require('tap')
|
|
7
|
+
const { fork } = require('child_process')
|
|
8
|
+
const writer = require('flush-write-stream')
|
|
9
|
+
const { once, getPathToNull } = require('./helper')
|
|
10
|
+
|
|
11
|
+
test('asynchronous logging', async ({ equal, teardown }) => {
|
|
12
|
+
const now = Date.now
|
|
13
|
+
const hostname = os.hostname
|
|
14
|
+
const proc = process
|
|
15
|
+
global.process = {
|
|
16
|
+
__proto__: process,
|
|
17
|
+
pid: 123456
|
|
18
|
+
}
|
|
19
|
+
Date.now = () => 1459875739796
|
|
20
|
+
os.hostname = () => 'abcdefghijklmnopqr'
|
|
21
|
+
delete require.cache[require.resolve('../')]
|
|
22
|
+
const bingo-logger = require('../')
|
|
23
|
+
let expected = ''
|
|
24
|
+
let actual = ''
|
|
25
|
+
const normal = bingo-logger(writer((s, enc, cb) => {
|
|
26
|
+
expected += s
|
|
27
|
+
cb()
|
|
28
|
+
}))
|
|
29
|
+
|
|
30
|
+
const dest = createWriteStream(getPathToNull())
|
|
31
|
+
dest.write = (s) => {
|
|
32
|
+
actual += s
|
|
33
|
+
}
|
|
34
|
+
const asyncLogger = bingo-logger(dest)
|
|
35
|
+
|
|
36
|
+
let i = 44
|
|
37
|
+
while (i--) {
|
|
38
|
+
normal.info('h')
|
|
39
|
+
asyncLogger.info('h')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const expected2 = expected.split('\n')[0]
|
|
43
|
+
let actual2 = ''
|
|
44
|
+
|
|
45
|
+
const child = fork(join(__dirname, '/fixtures/syncfalse.js'), { silent: true })
|
|
46
|
+
child.stdout.pipe(writer((s, enc, cb) => {
|
|
47
|
+
actual2 += s
|
|
48
|
+
cb()
|
|
49
|
+
}))
|
|
50
|
+
await once(child, 'close')
|
|
51
|
+
equal(actual, expected)
|
|
52
|
+
equal(actual2.trim(), expected2)
|
|
53
|
+
|
|
54
|
+
teardown(() => {
|
|
55
|
+
os.hostname = hostname
|
|
56
|
+
Date.now = now
|
|
57
|
+
global.process = proc
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('sync false with child', async ({ equal, teardown }) => {
|
|
62
|
+
const now = Date.now
|
|
63
|
+
const hostname = os.hostname
|
|
64
|
+
const proc = process
|
|
65
|
+
global.process = {
|
|
66
|
+
__proto__: process,
|
|
67
|
+
pid: 123456
|
|
68
|
+
}
|
|
69
|
+
Date.now = function () {
|
|
70
|
+
return 1459875739796
|
|
71
|
+
}
|
|
72
|
+
os.hostname = function () {
|
|
73
|
+
return 'abcdefghijklmnopqr'
|
|
74
|
+
}
|
|
75
|
+
delete require.cache[require.resolve('../')]
|
|
76
|
+
const bingo-logger = require('../')
|
|
77
|
+
let expected = ''
|
|
78
|
+
let actual = ''
|
|
79
|
+
const normal = bingo-logger(writer((s, enc, cb) => {
|
|
80
|
+
expected += s
|
|
81
|
+
cb()
|
|
82
|
+
})).child({ hello: 'world' })
|
|
83
|
+
|
|
84
|
+
const dest = createWriteStream(getPathToNull())
|
|
85
|
+
dest.write = function (s) { actual += s }
|
|
86
|
+
const asyncLogger = bingo-logger(dest).child({ hello: 'world' })
|
|
87
|
+
|
|
88
|
+
let i = 500
|
|
89
|
+
while (i--) {
|
|
90
|
+
normal.info('h')
|
|
91
|
+
asyncLogger.info('h')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
asyncLogger.flush()
|
|
95
|
+
|
|
96
|
+
const expected2 = expected.split('\n')[0]
|
|
97
|
+
let actual2 = ''
|
|
98
|
+
|
|
99
|
+
const child = fork(join(__dirname, '/fixtures/syncfalse-child.js'), { silent: true })
|
|
100
|
+
child.stdout.pipe(writer((s, enc, cb) => {
|
|
101
|
+
actual2 += s
|
|
102
|
+
cb()
|
|
103
|
+
}))
|
|
104
|
+
await once(child, 'close')
|
|
105
|
+
equal(actual, expected)
|
|
106
|
+
equal(actual2.trim(), expected2)
|
|
107
|
+
|
|
108
|
+
teardown(() => {
|
|
109
|
+
os.hostname = hostname
|
|
110
|
+
Date.now = now
|
|
111
|
+
global.process = proc
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
test('flush does nothing with sync true (default)', async () => {
|
|
116
|
+
const instance = require('..')()
|
|
117
|
+
instance.flush()
|
|
118
|
+
})
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/* eslint no-prototype-builtins: 0 */
|
|
4
|
+
|
|
5
|
+
const { test } = require('tap')
|
|
6
|
+
const { sink, once } = require('./helper')
|
|
7
|
+
const bingo-logger = require('../')
|
|
8
|
+
|
|
9
|
+
test('bingo-logger exposes standard time functions', async ({ ok }) => {
|
|
10
|
+
ok(bingo-logger.stdTimeFunctions)
|
|
11
|
+
ok(bingo-logger.stdTimeFunctions.epochTime)
|
|
12
|
+
ok(bingo-logger.stdTimeFunctions.unixTime)
|
|
13
|
+
ok(bingo-logger.stdTimeFunctions.nullTime)
|
|
14
|
+
ok(bingo-logger.stdTimeFunctions.isoTime)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
test('bingo-logger accepts external time functions', async ({ equal }) => {
|
|
18
|
+
const opts = {
|
|
19
|
+
timestamp: () => ',"time":"none"'
|
|
20
|
+
}
|
|
21
|
+
const stream = sink()
|
|
22
|
+
const instance = bingo-logger(opts, stream)
|
|
23
|
+
instance.info('foobar')
|
|
24
|
+
const result = await once(stream, 'data')
|
|
25
|
+
equal(result.hasOwnProperty('time'), true)
|
|
26
|
+
equal(result.time, 'none')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('bingo-logger accepts external time functions with custom label', async ({ equal }) => {
|
|
30
|
+
const opts = {
|
|
31
|
+
timestamp: () => ',"custom-time-label":"none"'
|
|
32
|
+
}
|
|
33
|
+
const stream = sink()
|
|
34
|
+
const instance = bingo-logger(opts, stream)
|
|
35
|
+
instance.info('foobar')
|
|
36
|
+
const result = await once(stream, 'data')
|
|
37
|
+
equal(result.hasOwnProperty('custom-time-label'), true)
|
|
38
|
+
equal(result['custom-time-label'], 'none')
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('inserts timestamp by default', async ({ ok, equal }) => {
|
|
42
|
+
const stream = sink()
|
|
43
|
+
const instance = bingo-logger(stream)
|
|
44
|
+
instance.info('foobar')
|
|
45
|
+
const result = await once(stream, 'data')
|
|
46
|
+
equal(result.hasOwnProperty('time'), true)
|
|
47
|
+
ok(new Date(result.time) <= new Date(), 'time is greater than timestamp')
|
|
48
|
+
equal(result.msg, 'foobar')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('omits timestamp when timestamp option is false', async ({ equal }) => {
|
|
52
|
+
const stream = sink()
|
|
53
|
+
const instance = bingo-logger({ timestamp: false }, stream)
|
|
54
|
+
instance.info('foobar')
|
|
55
|
+
const result = await once(stream, 'data')
|
|
56
|
+
equal(result.hasOwnProperty('time'), false)
|
|
57
|
+
equal(result.msg, 'foobar')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('inserts timestamp when timestamp option is true', async ({ ok, equal }) => {
|
|
61
|
+
const stream = sink()
|
|
62
|
+
const instance = bingo-logger({ timestamp: true }, stream)
|
|
63
|
+
instance.info('foobar')
|
|
64
|
+
const result = await once(stream, 'data')
|
|
65
|
+
equal(result.hasOwnProperty('time'), true)
|
|
66
|
+
ok(new Date(result.time) <= new Date(), 'time is greater than timestamp')
|
|
67
|
+
equal(result.msg, 'foobar')
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('child inserts timestamp by default', async ({ ok, equal }) => {
|
|
71
|
+
const stream = sink()
|
|
72
|
+
const logger = bingo-logger(stream)
|
|
73
|
+
const instance = logger.child({ component: 'child' })
|
|
74
|
+
instance.info('foobar')
|
|
75
|
+
const result = await once(stream, 'data')
|
|
76
|
+
equal(result.hasOwnProperty('time'), true)
|
|
77
|
+
ok(new Date(result.time) <= new Date(), 'time is greater than timestamp')
|
|
78
|
+
equal(result.msg, 'foobar')
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('child omits timestamp with option', async ({ equal }) => {
|
|
82
|
+
const stream = sink()
|
|
83
|
+
const logger = bingo-logger({ timestamp: false }, stream)
|
|
84
|
+
const instance = logger.child({ component: 'child' })
|
|
85
|
+
instance.info('foobar')
|
|
86
|
+
const result = await once(stream, 'data')
|
|
87
|
+
equal(result.hasOwnProperty('time'), false)
|
|
88
|
+
equal(result.msg, 'foobar')
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test('bingo-logger.stdTimeFunctions.unixTime returns seconds based timestamps', async ({ equal }) => {
|
|
92
|
+
const opts = {
|
|
93
|
+
timestamp: bingo-logger.stdTimeFunctions.unixTime
|
|
94
|
+
}
|
|
95
|
+
const stream = sink()
|
|
96
|
+
const instance = bingo-logger(opts, stream)
|
|
97
|
+
const now = Date.now
|
|
98
|
+
Date.now = () => 1531069919686
|
|
99
|
+
instance.info('foobar')
|
|
100
|
+
const result = await once(stream, 'data')
|
|
101
|
+
equal(result.hasOwnProperty('time'), true)
|
|
102
|
+
equal(result.time, 1531069920)
|
|
103
|
+
Date.now = now
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('bingo-logger.stdTimeFunctions.isoTime returns ISO 8601 timestamps', async ({ equal }) => {
|
|
107
|
+
const opts = {
|
|
108
|
+
timestamp: bingo-logger.stdTimeFunctions.isoTime
|
|
109
|
+
}
|
|
110
|
+
const stream = sink()
|
|
111
|
+
const instance = bingo-logger(opts, stream)
|
|
112
|
+
const ms = 1531069919686
|
|
113
|
+
const now = Date.now
|
|
114
|
+
Date.now = () => ms
|
|
115
|
+
const iso = new Date(ms).toISOString()
|
|
116
|
+
instance.info('foobar')
|
|
117
|
+
const result = await once(stream, 'data')
|
|
118
|
+
equal(result.hasOwnProperty('time'), true)
|
|
119
|
+
equal(result.time, iso)
|
|
120
|
+
Date.now = now
|
|
121
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('tap')
|
|
4
|
+
const { join } = require('path')
|
|
5
|
+
const { createReadStream } = require('fs')
|
|
6
|
+
const { promisify } = require('util')
|
|
7
|
+
const execa = require('execa')
|
|
8
|
+
const split = require('split2')
|
|
9
|
+
const stream = require('stream')
|
|
10
|
+
const { file } = require('../helper')
|
|
11
|
+
|
|
12
|
+
const pipeline = promisify(stream.pipeline)
|
|
13
|
+
const { Writable } = stream
|
|
14
|
+
const sleep = promisify(setTimeout)
|
|
15
|
+
|
|
16
|
+
test('eight million lines', async ({ equal, comment }) => {
|
|
17
|
+
const destination = file()
|
|
18
|
+
await execa(process.argv[0], [join(__dirname, '..', 'fixtures', 'transport-many-lines.js'), destination])
|
|
19
|
+
|
|
20
|
+
if (process.platform !== 'win32') {
|
|
21
|
+
try {
|
|
22
|
+
await execa('sync') // Wait for the file to be writen to disk
|
|
23
|
+
} catch {
|
|
24
|
+
// Just a fallback, this should be unreachable
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
await sleep(1000) // It seems that sync is not enough (even in POSIX systems)
|
|
28
|
+
|
|
29
|
+
const toWrite = 8 * 1000000
|
|
30
|
+
let count = 0
|
|
31
|
+
await pipeline(createReadStream(destination), split(), new Writable({
|
|
32
|
+
write (chunk, enc, cb) {
|
|
33
|
+
if (count % (toWrite / 10) === 0) {
|
|
34
|
+
comment(`read ${count}`)
|
|
35
|
+
}
|
|
36
|
+
count++
|
|
37
|
+
cb()
|
|
38
|
+
}
|
|
39
|
+
}))
|
|
40
|
+
equal(count, toWrite)
|
|
41
|
+
})
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const os = require('os')
|
|
4
|
+
const { join } = require('path')
|
|
5
|
+
const { readFile } = require('fs').promises
|
|
6
|
+
const { watchFileCreated, file } = require('../helper')
|
|
7
|
+
const { test } = require('tap')
|
|
8
|
+
const bingo-logger = require('../../bingo-logger')
|
|
9
|
+
|
|
10
|
+
const { pid } = process
|
|
11
|
+
const hostname = os.hostname()
|
|
12
|
+
|
|
13
|
+
test('bingo-logger.transport with destination overriden by bundler', async ({ same, teardown }) => {
|
|
14
|
+
globalThis.__bundlerPathsOverrides = {
|
|
15
|
+
foobar: join(__dirname, '..', 'fixtures', 'to-file-transport.js')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const destination = file()
|
|
19
|
+
const transport = bingo-logger.transport({
|
|
20
|
+
target: 'foobar',
|
|
21
|
+
options: { destination }
|
|
22
|
+
})
|
|
23
|
+
teardown(transport.end.bind(transport))
|
|
24
|
+
const instance = bingo-logger(transport)
|
|
25
|
+
instance.info('hello')
|
|
26
|
+
await watchFileCreated(destination)
|
|
27
|
+
const result = JSON.parse(await readFile(destination))
|
|
28
|
+
delete result.time
|
|
29
|
+
same(result, {
|
|
30
|
+
pid,
|
|
31
|
+
hostname,
|
|
32
|
+
level: 30,
|
|
33
|
+
msg: 'hello'
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
globalThis.__bundlerPathsOverrides = undefined
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('bingo-logger.transport with worker destination overriden by bundler', async ({ same, teardown }) => {
|
|
40
|
+
globalThis.__bundlerPathsOverrides = {
|
|
41
|
+
'bingo-logger-worker': join(__dirname, '..', '..', 'lib/worker.js')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const destination = file()
|
|
45
|
+
const transport = bingo-logger.transport({
|
|
46
|
+
targets: [
|
|
47
|
+
{
|
|
48
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
|
49
|
+
options: { destination }
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
})
|
|
53
|
+
teardown(transport.end.bind(transport))
|
|
54
|
+
const instance = bingo-logger(transport)
|
|
55
|
+
instance.info('hello')
|
|
56
|
+
await watchFileCreated(destination)
|
|
57
|
+
const result = JSON.parse(await readFile(destination))
|
|
58
|
+
delete result.time
|
|
59
|
+
same(result, {
|
|
60
|
+
pid,
|
|
61
|
+
hostname,
|
|
62
|
+
level: 30,
|
|
63
|
+
msg: 'hello'
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
globalThis.__bundlerPathsOverrides = undefined
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
test('bingo-logger.transport with worker-pipeline destination overriden by bundler', async ({ same, teardown }) => {
|
|
70
|
+
globalThis.__bundlerPathsOverrides = {
|
|
71
|
+
'bingo-logger-pipeline-worker': join(__dirname, '..', '..', 'lib/worker-pipeline.js')
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const destination = file()
|
|
75
|
+
const transport = bingo-logger.transport({
|
|
76
|
+
pipeline: [
|
|
77
|
+
{
|
|
78
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
|
79
|
+
options: { destination }
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
})
|
|
83
|
+
teardown(transport.end.bind(transport))
|
|
84
|
+
const instance = bingo-logger(transport)
|
|
85
|
+
instance.info('hello')
|
|
86
|
+
await watchFileCreated(destination)
|
|
87
|
+
const result = JSON.parse(await readFile(destination))
|
|
88
|
+
delete result.time
|
|
89
|
+
same(result, {
|
|
90
|
+
pid,
|
|
91
|
+
hostname,
|
|
92
|
+
level: 30,
|
|
93
|
+
msg: 'hello'
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
globalThis.__bundlerPathsOverrides = undefined
|
|
97
|
+
})
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { join } = require('path')
|
|
4
|
+
const { test } = require('tap')
|
|
5
|
+
const execa = require('execa')
|
|
6
|
+
|
|
7
|
+
test('when using a custom transport outside node_modules, the first file outside node_modules should be used', async function (t) {
|
|
8
|
+
const evalApp = join(__dirname, '../', '/fixtures/eval/index.js')
|
|
9
|
+
const { stdout } = await execa(process.argv[0], [evalApp])
|
|
10
|
+
t.match(stdout, /done!/)
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test('when using a custom transport where some files in stacktrace are in the node_modules, the first file outside node_modules should be used', async function (t) {
|
|
14
|
+
const evalApp = join(__dirname, '../', '/fixtures/eval/node_modules/2-files.js')
|
|
15
|
+
const { stdout } = await execa(process.argv[0], [evalApp])
|
|
16
|
+
t.match(stdout, /done!/)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('when using a custom transport where all files in stacktrace are in the node_modules, the first file inside node_modules should be used', async function (t) {
|
|
20
|
+
const evalApp = join(__dirname, '../', '/fixtures/eval/node_modules/14-files.js')
|
|
21
|
+
const { stdout } = await execa(process.argv[0], [evalApp])
|
|
22
|
+
t.match(stdout, /done!/)
|
|
23
|
+
})
|