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,546 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const os = require('os')
|
|
4
|
+
const { join } = require('path')
|
|
5
|
+
const { once } = require('events')
|
|
6
|
+
const { readFile, writeFile } = require('fs').promises
|
|
7
|
+
const { watchFileCreated, watchForWrite, file } = require('../helper')
|
|
8
|
+
const { test } = require('tap')
|
|
9
|
+
const bingo-logger = require('../../')
|
|
10
|
+
const url = require('url')
|
|
11
|
+
const strip = require('strip-ansi')
|
|
12
|
+
const execa = require('execa')
|
|
13
|
+
const writer = require('flush-write-stream')
|
|
14
|
+
const rimraf = require('rimraf')
|
|
15
|
+
const { tmpdir } = os
|
|
16
|
+
|
|
17
|
+
const pid = process.pid
|
|
18
|
+
const hostname = os.hostname()
|
|
19
|
+
|
|
20
|
+
test('bingo-logger.transport with file', async ({ same, teardown }) => {
|
|
21
|
+
const destination = file()
|
|
22
|
+
const transport = bingo-logger.transport({
|
|
23
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
|
24
|
+
options: { destination }
|
|
25
|
+
})
|
|
26
|
+
teardown(transport.end.bind(transport))
|
|
27
|
+
const instance = bingo-logger(transport)
|
|
28
|
+
instance.info('hello')
|
|
29
|
+
await watchFileCreated(destination)
|
|
30
|
+
const result = JSON.parse(await readFile(destination))
|
|
31
|
+
delete result.time
|
|
32
|
+
same(result, {
|
|
33
|
+
pid,
|
|
34
|
+
hostname,
|
|
35
|
+
level: 30,
|
|
36
|
+
msg: 'hello'
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('bingo-logger.transport with file (no options + error handling)', async ({ equal }) => {
|
|
41
|
+
const transport = bingo-logger.transport({
|
|
42
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js')
|
|
43
|
+
})
|
|
44
|
+
const [err] = await once(transport, 'error')
|
|
45
|
+
equal(err.message, 'kaboom')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('bingo-logger.transport with file URL', async ({ same, teardown }) => {
|
|
49
|
+
const destination = file()
|
|
50
|
+
const transport = bingo-logger.transport({
|
|
51
|
+
target: url.pathToFileURL(join(__dirname, '..', 'fixtures', 'to-file-transport.js')).href,
|
|
52
|
+
options: { destination }
|
|
53
|
+
})
|
|
54
|
+
teardown(transport.end.bind(transport))
|
|
55
|
+
const instance = bingo-logger(transport)
|
|
56
|
+
instance.info('hello')
|
|
57
|
+
await watchFileCreated(destination)
|
|
58
|
+
const result = JSON.parse(await readFile(destination))
|
|
59
|
+
delete result.time
|
|
60
|
+
same(result, {
|
|
61
|
+
pid,
|
|
62
|
+
hostname,
|
|
63
|
+
level: 30,
|
|
64
|
+
msg: 'hello'
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('bingo-logger.transport errors if file does not exists', ({ plan, pass }) => {
|
|
69
|
+
plan(1)
|
|
70
|
+
const instance = bingo-logger.transport({
|
|
71
|
+
target: join(__dirname, '..', 'fixtures', 'non-existent-file'),
|
|
72
|
+
worker: {
|
|
73
|
+
stdin: true,
|
|
74
|
+
stdout: true,
|
|
75
|
+
stderr: true
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
instance.on('error', function () {
|
|
79
|
+
pass('error received')
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('bingo-logger.transport errors if transport worker module does not export a function', ({ plan, equal }) => {
|
|
84
|
+
// TODO: add case for non-pipelined single target (needs changes in thread-stream)
|
|
85
|
+
plan(2)
|
|
86
|
+
const manyTargetsInstance = bingo-logger.transport({
|
|
87
|
+
targets: [{
|
|
88
|
+
level: 'info',
|
|
89
|
+
target: join(__dirname, '..', 'fixtures', 'transport-wrong-export-type.js')
|
|
90
|
+
}, {
|
|
91
|
+
level: 'info',
|
|
92
|
+
target: join(__dirname, '..', 'fixtures', 'transport-wrong-export-type.js')
|
|
93
|
+
}]
|
|
94
|
+
})
|
|
95
|
+
manyTargetsInstance.on('error', function (e) {
|
|
96
|
+
equal(e.message, 'exported worker is not a function')
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
const pipelinedInstance = bingo-logger.transport({
|
|
100
|
+
pipeline: [{
|
|
101
|
+
target: join(__dirname, '..', 'fixtures', 'transport-wrong-export-type.js')
|
|
102
|
+
}]
|
|
103
|
+
})
|
|
104
|
+
pipelinedInstance.on('error', function (e) {
|
|
105
|
+
equal(e.message, 'exported worker is not a function')
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test('bingo-logger.transport with esm', async ({ same, teardown }) => {
|
|
110
|
+
const destination = file()
|
|
111
|
+
const transport = bingo-logger.transport({
|
|
112
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.mjs'),
|
|
113
|
+
options: { destination }
|
|
114
|
+
})
|
|
115
|
+
const instance = bingo-logger(transport)
|
|
116
|
+
teardown(transport.end.bind(transport))
|
|
117
|
+
instance.info('hello')
|
|
118
|
+
await watchFileCreated(destination)
|
|
119
|
+
const result = JSON.parse(await readFile(destination))
|
|
120
|
+
delete result.time
|
|
121
|
+
same(result, {
|
|
122
|
+
pid,
|
|
123
|
+
hostname,
|
|
124
|
+
level: 30,
|
|
125
|
+
msg: 'hello'
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test('bingo-logger.transport with two files', async ({ same, teardown }) => {
|
|
130
|
+
const dest1 = file()
|
|
131
|
+
const dest2 = file()
|
|
132
|
+
const transport = bingo-logger.transport({
|
|
133
|
+
targets: [{
|
|
134
|
+
level: 'info',
|
|
135
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
|
136
|
+
options: { destination: dest1 }
|
|
137
|
+
}, {
|
|
138
|
+
level: 'info',
|
|
139
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
|
140
|
+
options: { destination: dest2 }
|
|
141
|
+
}]
|
|
142
|
+
})
|
|
143
|
+
teardown(transport.end.bind(transport))
|
|
144
|
+
const instance = bingo-logger(transport)
|
|
145
|
+
instance.info('hello')
|
|
146
|
+
await Promise.all([watchFileCreated(dest1), watchFileCreated(dest2)])
|
|
147
|
+
const result1 = JSON.parse(await readFile(dest1))
|
|
148
|
+
delete result1.time
|
|
149
|
+
same(result1, {
|
|
150
|
+
pid,
|
|
151
|
+
hostname,
|
|
152
|
+
level: 30,
|
|
153
|
+
msg: 'hello'
|
|
154
|
+
})
|
|
155
|
+
const result2 = JSON.parse(await readFile(dest2))
|
|
156
|
+
delete result2.time
|
|
157
|
+
same(result2, {
|
|
158
|
+
pid,
|
|
159
|
+
hostname,
|
|
160
|
+
level: 30,
|
|
161
|
+
msg: 'hello'
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
test('bingo-logger.transport with two files and custom levels', async ({ same, teardown }) => {
|
|
166
|
+
const dest1 = file()
|
|
167
|
+
const dest2 = file()
|
|
168
|
+
const transport = bingo-logger.transport({
|
|
169
|
+
targets: [{
|
|
170
|
+
level: 'info',
|
|
171
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
|
172
|
+
options: { destination: dest1 }
|
|
173
|
+
}, {
|
|
174
|
+
level: 'foo',
|
|
175
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
|
176
|
+
options: { destination: dest2 }
|
|
177
|
+
}],
|
|
178
|
+
levels: { trace: 10, debug: 20, info: 30, warn: 40, error: 50, fatal: 60, foo: 25 }
|
|
179
|
+
})
|
|
180
|
+
teardown(transport.end.bind(transport))
|
|
181
|
+
const instance = bingo-logger(transport)
|
|
182
|
+
instance.info('hello')
|
|
183
|
+
await Promise.all([watchFileCreated(dest1), watchFileCreated(dest2)])
|
|
184
|
+
const result1 = JSON.parse(await readFile(dest1))
|
|
185
|
+
delete result1.time
|
|
186
|
+
same(result1, {
|
|
187
|
+
pid,
|
|
188
|
+
hostname,
|
|
189
|
+
level: 30,
|
|
190
|
+
msg: 'hello'
|
|
191
|
+
})
|
|
192
|
+
const result2 = JSON.parse(await readFile(dest2))
|
|
193
|
+
delete result2.time
|
|
194
|
+
same(result2, {
|
|
195
|
+
pid,
|
|
196
|
+
hostname,
|
|
197
|
+
level: 30,
|
|
198
|
+
msg: 'hello'
|
|
199
|
+
})
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
test('bingo-logger.transport with an array including a bingo-logger-pretty destination', async ({ same, match, teardown }) => {
|
|
203
|
+
const dest1 = file()
|
|
204
|
+
const dest2 = file()
|
|
205
|
+
const transport = bingo-logger.transport({
|
|
206
|
+
targets: [{
|
|
207
|
+
level: 'info',
|
|
208
|
+
target: 'bingo-logger/file',
|
|
209
|
+
options: {
|
|
210
|
+
destination: dest1
|
|
211
|
+
}
|
|
212
|
+
}, {
|
|
213
|
+
level: 'info',
|
|
214
|
+
target: 'bingo-logger-pretty',
|
|
215
|
+
options: {
|
|
216
|
+
destination: dest2
|
|
217
|
+
}
|
|
218
|
+
}]
|
|
219
|
+
})
|
|
220
|
+
teardown(transport.end.bind(transport))
|
|
221
|
+
const instance = bingo-logger(transport)
|
|
222
|
+
instance.info('hello')
|
|
223
|
+
await Promise.all([watchFileCreated(dest1), watchFileCreated(dest2)])
|
|
224
|
+
const result1 = JSON.parse(await readFile(dest1))
|
|
225
|
+
delete result1.time
|
|
226
|
+
same(result1, {
|
|
227
|
+
pid,
|
|
228
|
+
hostname,
|
|
229
|
+
level: 30,
|
|
230
|
+
msg: 'hello'
|
|
231
|
+
})
|
|
232
|
+
const actual = (await readFile(dest2)).toString()
|
|
233
|
+
match(strip(actual), /\[.*\] INFO.*hello/)
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
test('no transport.end()', async ({ same, teardown }) => {
|
|
237
|
+
const destination = file()
|
|
238
|
+
const transport = bingo-logger.transport({
|
|
239
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
|
240
|
+
options: { destination }
|
|
241
|
+
})
|
|
242
|
+
const instance = bingo-logger(transport)
|
|
243
|
+
instance.info('hello')
|
|
244
|
+
await watchFileCreated(destination)
|
|
245
|
+
const result = JSON.parse(await readFile(destination))
|
|
246
|
+
delete result.time
|
|
247
|
+
same(result, {
|
|
248
|
+
pid,
|
|
249
|
+
hostname,
|
|
250
|
+
level: 30,
|
|
251
|
+
msg: 'hello'
|
|
252
|
+
})
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
test('autoEnd = false', async ({ equal, same, teardown }) => {
|
|
256
|
+
const destination = file()
|
|
257
|
+
const count = process.listenerCount('exit')
|
|
258
|
+
const transport = bingo-logger.transport({
|
|
259
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
|
260
|
+
options: { destination },
|
|
261
|
+
worker: { autoEnd: false }
|
|
262
|
+
})
|
|
263
|
+
teardown(transport.end.bind(transport))
|
|
264
|
+
await once(transport, 'ready')
|
|
265
|
+
|
|
266
|
+
const instance = bingo-logger(transport)
|
|
267
|
+
instance.info('hello')
|
|
268
|
+
|
|
269
|
+
await watchFileCreated(destination)
|
|
270
|
+
|
|
271
|
+
equal(count, process.listenerCount('exit'))
|
|
272
|
+
|
|
273
|
+
const result = JSON.parse(await readFile(destination))
|
|
274
|
+
delete result.time
|
|
275
|
+
same(result, {
|
|
276
|
+
pid,
|
|
277
|
+
hostname,
|
|
278
|
+
level: 30,
|
|
279
|
+
msg: 'hello'
|
|
280
|
+
})
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
test('bingo-logger.transport with target and targets', async ({ fail, equal }) => {
|
|
284
|
+
try {
|
|
285
|
+
bingo-logger.transport({
|
|
286
|
+
target: '/a/file',
|
|
287
|
+
targets: [{
|
|
288
|
+
target: '/a/file'
|
|
289
|
+
}]
|
|
290
|
+
})
|
|
291
|
+
fail('must throw')
|
|
292
|
+
} catch (err) {
|
|
293
|
+
equal(err.message, 'only one of target or targets can be specified')
|
|
294
|
+
}
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
test('bingo-logger.transport with target bingo-logger/file', async ({ same, teardown }) => {
|
|
298
|
+
const destination = file()
|
|
299
|
+
const transport = bingo-logger.transport({
|
|
300
|
+
target: 'bingo-logger/file',
|
|
301
|
+
options: { destination }
|
|
302
|
+
})
|
|
303
|
+
teardown(transport.end.bind(transport))
|
|
304
|
+
const instance = bingo-logger(transport)
|
|
305
|
+
instance.info('hello')
|
|
306
|
+
await watchFileCreated(destination)
|
|
307
|
+
const result = JSON.parse(await readFile(destination))
|
|
308
|
+
delete result.time
|
|
309
|
+
same(result, {
|
|
310
|
+
pid,
|
|
311
|
+
hostname,
|
|
312
|
+
level: 30,
|
|
313
|
+
msg: 'hello'
|
|
314
|
+
})
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
test('bingo-logger.transport with target bingo-logger/file and mkdir option', async ({ same, teardown }) => {
|
|
318
|
+
const folder = join(tmpdir(), `bingo-logger-${process.pid}-mkdir-transport-file`)
|
|
319
|
+
const destination = join(folder, 'log.txt')
|
|
320
|
+
teardown(() => {
|
|
321
|
+
try {
|
|
322
|
+
rimraf.sync(folder)
|
|
323
|
+
} catch (err) {
|
|
324
|
+
// ignore
|
|
325
|
+
}
|
|
326
|
+
})
|
|
327
|
+
const transport = bingo-logger.transport({
|
|
328
|
+
target: 'bingo-logger/file',
|
|
329
|
+
options: { destination, mkdir: true }
|
|
330
|
+
})
|
|
331
|
+
teardown(transport.end.bind(transport))
|
|
332
|
+
const instance = bingo-logger(transport)
|
|
333
|
+
instance.info('hello')
|
|
334
|
+
await watchFileCreated(destination)
|
|
335
|
+
const result = JSON.parse(await readFile(destination))
|
|
336
|
+
delete result.time
|
|
337
|
+
same(result, {
|
|
338
|
+
pid,
|
|
339
|
+
hostname,
|
|
340
|
+
level: 30,
|
|
341
|
+
msg: 'hello'
|
|
342
|
+
})
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
test('bingo-logger.transport with target bingo-logger/file and append option', async ({ same, teardown }) => {
|
|
346
|
+
const destination = file()
|
|
347
|
+
await writeFile(destination, JSON.stringify({ pid, hostname, time: Date.now(), level: 30, msg: 'hello' }))
|
|
348
|
+
const transport = bingo-logger.transport({
|
|
349
|
+
target: 'bingo-logger/file',
|
|
350
|
+
options: { destination, append: false }
|
|
351
|
+
})
|
|
352
|
+
teardown(transport.end.bind(transport))
|
|
353
|
+
const instance = bingo-logger(transport)
|
|
354
|
+
instance.info('goodbye')
|
|
355
|
+
await watchForWrite(destination, '"goodbye"')
|
|
356
|
+
const result = JSON.parse(await readFile(destination))
|
|
357
|
+
delete result.time
|
|
358
|
+
same(result, {
|
|
359
|
+
pid,
|
|
360
|
+
hostname,
|
|
361
|
+
level: 30,
|
|
362
|
+
msg: 'goodbye'
|
|
363
|
+
})
|
|
364
|
+
})
|
|
365
|
+
|
|
366
|
+
test('bingo-logger.transport should error with unknown target', async ({ fail, equal }) => {
|
|
367
|
+
try {
|
|
368
|
+
bingo-logger.transport({
|
|
369
|
+
target: 'origin',
|
|
370
|
+
caller: 'unknown-file.js'
|
|
371
|
+
})
|
|
372
|
+
fail('must throw')
|
|
373
|
+
} catch (err) {
|
|
374
|
+
equal(err.message, 'unable to determine transport target for "origin"')
|
|
375
|
+
}
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
test('bingo-logger.transport with target bingo-logger-pretty', async ({ match, teardown }) => {
|
|
379
|
+
const destination = file()
|
|
380
|
+
const transport = bingo-logger.transport({
|
|
381
|
+
target: 'bingo-logger-pretty',
|
|
382
|
+
options: { destination }
|
|
383
|
+
})
|
|
384
|
+
teardown(transport.end.bind(transport))
|
|
385
|
+
const instance = bingo-logger(transport)
|
|
386
|
+
instance.info('hello')
|
|
387
|
+
await watchFileCreated(destination)
|
|
388
|
+
const actual = await readFile(destination, 'utf8')
|
|
389
|
+
match(strip(actual), /\[.*\] INFO.*hello/)
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
test('stdout in worker', async ({ not }) => {
|
|
393
|
+
let actual = ''
|
|
394
|
+
const child = execa(process.argv[0], [join(__dirname, '..', 'fixtures', 'transport-main.js')])
|
|
395
|
+
|
|
396
|
+
child.stdout.pipe(writer((s, enc, cb) => {
|
|
397
|
+
actual += s
|
|
398
|
+
cb()
|
|
399
|
+
}))
|
|
400
|
+
await once(child, 'close')
|
|
401
|
+
not(strip(actual).match(/Hello/), null)
|
|
402
|
+
})
|
|
403
|
+
|
|
404
|
+
test('log and exit on ready', async ({ not }) => {
|
|
405
|
+
let actual = ''
|
|
406
|
+
const child = execa(process.argv[0], [join(__dirname, '..', 'fixtures', 'transport-exit-on-ready.js')])
|
|
407
|
+
|
|
408
|
+
child.stdout.pipe(writer((s, enc, cb) => {
|
|
409
|
+
actual += s
|
|
410
|
+
cb()
|
|
411
|
+
}))
|
|
412
|
+
await once(child, 'close')
|
|
413
|
+
not(strip(actual).match(/Hello/), null)
|
|
414
|
+
})
|
|
415
|
+
|
|
416
|
+
test('log and exit before ready', async ({ not }) => {
|
|
417
|
+
let actual = ''
|
|
418
|
+
const child = execa(process.argv[0], [join(__dirname, '..', 'fixtures', 'transport-exit-immediately.js')])
|
|
419
|
+
|
|
420
|
+
child.stdout.pipe(writer((s, enc, cb) => {
|
|
421
|
+
actual += s
|
|
422
|
+
cb()
|
|
423
|
+
}))
|
|
424
|
+
await once(child, 'close')
|
|
425
|
+
not(strip(actual).match(/Hello/), null)
|
|
426
|
+
})
|
|
427
|
+
|
|
428
|
+
test('log and exit before ready with async dest', async ({ not }) => {
|
|
429
|
+
const destination = file()
|
|
430
|
+
const child = execa(process.argv[0], [join(__dirname, '..', 'fixtures', 'transport-exit-immediately-with-async-dest.js'), destination])
|
|
431
|
+
|
|
432
|
+
await once(child, 'exit')
|
|
433
|
+
|
|
434
|
+
const actual = await readFile(destination, 'utf8')
|
|
435
|
+
not(strip(actual).match(/HELLO/), null)
|
|
436
|
+
not(strip(actual).match(/WORLD/), null)
|
|
437
|
+
})
|
|
438
|
+
|
|
439
|
+
test('string integer destination', async ({ not }) => {
|
|
440
|
+
let actual = ''
|
|
441
|
+
const child = execa(process.argv[0], [join(__dirname, '..', 'fixtures', 'transport-string-stdout.js')])
|
|
442
|
+
|
|
443
|
+
child.stdout.pipe(writer((s, enc, cb) => {
|
|
444
|
+
actual += s
|
|
445
|
+
cb()
|
|
446
|
+
}))
|
|
447
|
+
await once(child, 'close')
|
|
448
|
+
not(strip(actual).match(/Hello/), null)
|
|
449
|
+
})
|
|
450
|
+
|
|
451
|
+
test('bingo-logger transport options with target', async ({ teardown, same }) => {
|
|
452
|
+
const destination = file()
|
|
453
|
+
const instance = bingo-logger({
|
|
454
|
+
transport: {
|
|
455
|
+
target: 'bingo-logger/file',
|
|
456
|
+
options: { destination }
|
|
457
|
+
}
|
|
458
|
+
})
|
|
459
|
+
const transportStream = instance[bingo-logger.symbols.streamSym]
|
|
460
|
+
teardown(transportStream.end.bind(transportStream))
|
|
461
|
+
instance.info('transport option test')
|
|
462
|
+
await watchFileCreated(destination)
|
|
463
|
+
const result = JSON.parse(await readFile(destination))
|
|
464
|
+
delete result.time
|
|
465
|
+
same(result, {
|
|
466
|
+
pid,
|
|
467
|
+
hostname,
|
|
468
|
+
level: 30,
|
|
469
|
+
msg: 'transport option test'
|
|
470
|
+
})
|
|
471
|
+
})
|
|
472
|
+
|
|
473
|
+
test('bingo-logger transport options with targets', async ({ teardown, same }) => {
|
|
474
|
+
const dest1 = file()
|
|
475
|
+
const dest2 = file()
|
|
476
|
+
const instance = bingo-logger({
|
|
477
|
+
transport: {
|
|
478
|
+
targets: [
|
|
479
|
+
{ target: 'bingo-logger/file', options: { destination: dest1 } },
|
|
480
|
+
{ target: 'bingo-logger/file', options: { destination: dest2 } }
|
|
481
|
+
]
|
|
482
|
+
}
|
|
483
|
+
})
|
|
484
|
+
const transportStream = instance[bingo-logger.symbols.streamSym]
|
|
485
|
+
teardown(transportStream.end.bind(transportStream))
|
|
486
|
+
instance.info('transport option test')
|
|
487
|
+
|
|
488
|
+
await Promise.all([watchFileCreated(dest1), watchFileCreated(dest2)])
|
|
489
|
+
const result1 = JSON.parse(await readFile(dest1))
|
|
490
|
+
delete result1.time
|
|
491
|
+
same(result1, {
|
|
492
|
+
pid,
|
|
493
|
+
hostname,
|
|
494
|
+
level: 30,
|
|
495
|
+
msg: 'transport option test'
|
|
496
|
+
})
|
|
497
|
+
const result2 = JSON.parse(await readFile(dest2))
|
|
498
|
+
delete result2.time
|
|
499
|
+
same(result2, {
|
|
500
|
+
pid,
|
|
501
|
+
hostname,
|
|
502
|
+
level: 30,
|
|
503
|
+
msg: 'transport option test'
|
|
504
|
+
})
|
|
505
|
+
})
|
|
506
|
+
|
|
507
|
+
test('transport options with target and targets', async ({ fail, equal }) => {
|
|
508
|
+
try {
|
|
509
|
+
bingo-logger({
|
|
510
|
+
transport: {
|
|
511
|
+
target: {},
|
|
512
|
+
targets: {}
|
|
513
|
+
}
|
|
514
|
+
})
|
|
515
|
+
fail('must throw')
|
|
516
|
+
} catch (err) {
|
|
517
|
+
equal(err.message, 'only one of target or targets can be specified')
|
|
518
|
+
}
|
|
519
|
+
})
|
|
520
|
+
|
|
521
|
+
test('transport options with target and stream', async ({ fail, equal }) => {
|
|
522
|
+
try {
|
|
523
|
+
bingo-logger({
|
|
524
|
+
transport: {
|
|
525
|
+
target: {}
|
|
526
|
+
}
|
|
527
|
+
}, '/log/null')
|
|
528
|
+
fail('must throw')
|
|
529
|
+
} catch (err) {
|
|
530
|
+
equal(err.message, 'only one of option.transport or stream can be specified')
|
|
531
|
+
}
|
|
532
|
+
})
|
|
533
|
+
|
|
534
|
+
test('transport options with stream', async ({ fail, equal, teardown }) => {
|
|
535
|
+
try {
|
|
536
|
+
const dest1 = file()
|
|
537
|
+
const transportStream = bingo-logger.transport({ target: 'bingo-logger/file', options: { destination: dest1 } })
|
|
538
|
+
teardown(transportStream.end.bind(transportStream))
|
|
539
|
+
bingo-logger({
|
|
540
|
+
transport: transportStream
|
|
541
|
+
})
|
|
542
|
+
fail('must throw')
|
|
543
|
+
} catch (err) {
|
|
544
|
+
equal(err.message, 'option.transport do not allow stream, please pass to option directly. e.g. bingo-logger(transport)')
|
|
545
|
+
}
|
|
546
|
+
})
|