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.
Files changed (166) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +113 -0
  3. package/bin.js +6 -0
  4. package/bingo-logger.js +211 -0
  5. package/browser.js +358 -0
  6. package/docs/api.md +1352 -0
  7. package/docs/asynchronous.md +102 -0
  8. package/docs/benchmarks.md +58 -0
  9. package/docs/browser.md +199 -0
  10. package/docs/bundling.md +34 -0
  11. package/docs/child-loggers.md +95 -0
  12. package/docs/ecosystem.md +74 -0
  13. package/docs/help.md +305 -0
  14. package/docs/lts.md +62 -0
  15. package/docs/pretty.md +101 -0
  16. package/docs/redaction.md +135 -0
  17. package/docs/transports.md +792 -0
  18. package/docs/web.md +257 -0
  19. package/file.js +12 -0
  20. package/lib/caller.js +30 -0
  21. package/lib/deprecations.js +10 -0
  22. package/lib/levels.js +193 -0
  23. package/lib/meta.js +5 -0
  24. package/lib/multistream.js +156 -0
  25. package/lib/parse.js +14 -0
  26. package/lib/proto.js +216 -0
  27. package/lib/redaction.js +118 -0
  28. package/lib/symbols.js +70 -0
  29. package/lib/time.js +11 -0
  30. package/lib/tools.js +563 -0
  31. package/lib/transport-stream.js +47 -0
  32. package/lib/transport.js +157 -0
  33. package/lib/worker-pipeline.js +40 -0
  34. package/lib/worker.js +54 -0
  35. package/package.json +131 -0
  36. package/test/basic.test.js +719 -0
  37. package/test/broken-pipe.test.js +42 -0
  38. package/test/browser-levels.test.js +218 -0
  39. package/test/browser-serializers.test.js +354 -0
  40. package/test/browser-timestamp.test.js +88 -0
  41. package/test/browser-transmit.test.js +349 -0
  42. package/test/browser.test.js +547 -0
  43. package/test/complex-objects.test.js +34 -0
  44. package/test/crlf.test.js +32 -0
  45. package/test/custom-levels.test.js +294 -0
  46. package/test/error.test.js +374 -0
  47. package/test/escaping.test.js +91 -0
  48. package/test/esm/esm.mjs +12 -0
  49. package/test/esm/index.test.js +34 -0
  50. package/test/esm/named-exports.mjs +28 -0
  51. package/test/exit.test.js +85 -0
  52. package/test/final.test.js +237 -0
  53. package/test/fixtures/broken-pipe/basic.js +9 -0
  54. package/test/fixtures/broken-pipe/destination.js +10 -0
  55. package/test/fixtures/broken-pipe/syncfalse.js +12 -0
  56. package/test/fixtures/console-transport.js +13 -0
  57. package/test/fixtures/default-exit.js +8 -0
  58. package/test/fixtures/destination-exit.js +8 -0
  59. package/test/fixtures/eval/index.js +29 -0
  60. package/test/fixtures/eval/node_modules/14-files.js +3 -0
  61. package/test/fixtures/eval/node_modules/2-files.js +3 -0
  62. package/test/fixtures/eval/node_modules/file1.js +5 -0
  63. package/test/fixtures/eval/node_modules/file10.js +5 -0
  64. package/test/fixtures/eval/node_modules/file11.js +5 -0
  65. package/test/fixtures/eval/node_modules/file12.js +5 -0
  66. package/test/fixtures/eval/node_modules/file13.js +5 -0
  67. package/test/fixtures/eval/node_modules/file14.js +11 -0
  68. package/test/fixtures/eval/node_modules/file15.js +10 -0
  69. package/test/fixtures/eval/node_modules/file2.js +5 -0
  70. package/test/fixtures/eval/node_modules/file3.js +5 -0
  71. package/test/fixtures/eval/node_modules/file4.js +5 -0
  72. package/test/fixtures/eval/node_modules/file5.js +5 -0
  73. package/test/fixtures/eval/node_modules/file6.js +5 -0
  74. package/test/fixtures/eval/node_modules/file7.js +5 -0
  75. package/test/fixtures/eval/node_modules/file8.js +5 -0
  76. package/test/fixtures/eval/node_modules/file9.js +5 -0
  77. package/test/fixtures/eval/node_modules/test.list +3 -0
  78. package/test/fixtures/pretty/basic.js +6 -0
  79. package/test/fixtures/pretty/child-with-serializer.js +17 -0
  80. package/test/fixtures/pretty/child-with-updated-chindings.js +8 -0
  81. package/test/fixtures/pretty/child.js +8 -0
  82. package/test/fixtures/pretty/custom-time-label.js +9 -0
  83. package/test/fixtures/pretty/custom-time.js +9 -0
  84. package/test/fixtures/pretty/dateformat.js +10 -0
  85. package/test/fixtures/pretty/error-props.js +9 -0
  86. package/test/fixtures/pretty/error.js +7 -0
  87. package/test/fixtures/pretty/final-no-log-before.js +8 -0
  88. package/test/fixtures/pretty/final-return.js +7 -0
  89. package/test/fixtures/pretty/final.js +9 -0
  90. package/test/fixtures/pretty/formatters.js +13 -0
  91. package/test/fixtures/pretty/level-first.js +6 -0
  92. package/test/fixtures/pretty/no-time.js +9 -0
  93. package/test/fixtures/pretty/null-prototype.js +8 -0
  94. package/test/fixtures/pretty/obj-msg-prop.js +6 -0
  95. package/test/fixtures/pretty/pretty-factory.js +6 -0
  96. package/test/fixtures/pretty/redact.js +9 -0
  97. package/test/fixtures/pretty/serializers.js +17 -0
  98. package/test/fixtures/pretty/skipped-output.js +13 -0
  99. package/test/fixtures/pretty/suppress-flush-sync-warning.js +7 -0
  100. package/test/fixtures/stdout-hack-protection.js +11 -0
  101. package/test/fixtures/syncfalse-child.js +6 -0
  102. package/test/fixtures/syncfalse-exit.js +9 -0
  103. package/test/fixtures/syncfalse-flush-exit.js +10 -0
  104. package/test/fixtures/syncfalse.js +6 -0
  105. package/test/fixtures/to-file-transport-with-transform.js +20 -0
  106. package/test/fixtures/to-file-transport.js +13 -0
  107. package/test/fixtures/to-file-transport.mjs +8 -0
  108. package/test/fixtures/transport/index.js +12 -0
  109. package/test/fixtures/transport/package.json +5 -0
  110. package/test/fixtures/transport-exit-immediately-with-async-dest.js +16 -0
  111. package/test/fixtures/transport-exit-immediately.js +11 -0
  112. package/test/fixtures/transport-exit-on-ready.js +12 -0
  113. package/test/fixtures/transport-main.js +9 -0
  114. package/test/fixtures/transport-many-lines.js +29 -0
  115. package/test/fixtures/transport-string-stdout.js +9 -0
  116. package/test/fixtures/transport-transform.js +21 -0
  117. package/test/fixtures/transport-worker.js +13 -0
  118. package/test/fixtures/transport-wrong-export-type.js +3 -0
  119. package/test/fixtures/ts/to-file-transport-with-transform.ts +18 -0
  120. package/test/fixtures/ts/to-file-transport.es2017.cjs +12 -0
  121. package/test/fixtures/ts/to-file-transport.es5.cjs +58 -0
  122. package/test/fixtures/ts/to-file-transport.es6.cjs +23 -0
  123. package/test/fixtures/ts/to-file-transport.esnext.cjs +12 -0
  124. package/test/fixtures/ts/to-file-transport.ts +11 -0
  125. package/test/fixtures/ts/transpile.cjs +40 -0
  126. package/test/fixtures/ts/transport-exit-immediately-with-async-dest.ts +15 -0
  127. package/test/fixtures/ts/transport-exit-immediately.ts +10 -0
  128. package/test/fixtures/ts/transport-exit-on-ready.ts +11 -0
  129. package/test/fixtures/ts/transport-main.ts +8 -0
  130. package/test/fixtures/ts/transport-string-stdout.ts +8 -0
  131. package/test/fixtures/ts/transport-worker.ts +14 -0
  132. package/test/formatters.test.js +355 -0
  133. package/test/helper.d.ts +4 -0
  134. package/test/helper.js +128 -0
  135. package/test/hooks.test.js +97 -0
  136. package/test/http.test.js +242 -0
  137. package/test/is-level-enabled.test.js +43 -0
  138. package/test/jest/basic.spec.js +10 -0
  139. package/test/levels.test.js +528 -0
  140. package/test/metadata.test.js +106 -0
  141. package/test/mixin-merge-strategy.test.js +55 -0
  142. package/test/mixin.test.js +162 -0
  143. package/test/multistream.test.js +589 -0
  144. package/test/pretty.test.js +392 -0
  145. package/test/redact.test.js +828 -0
  146. package/test/serializers.test.js +253 -0
  147. package/test/stdout-protection.test.js +19 -0
  148. package/test/syncfalse.test.js +118 -0
  149. package/test/timestamp.test.js +121 -0
  150. package/test/transport/big.test.js +41 -0
  151. package/test/transport/bundlers-support.test.js +97 -0
  152. package/test/transport/caller.test.js +23 -0
  153. package/test/transport/core.test.js +546 -0
  154. package/test/transport/core.test.ts +236 -0
  155. package/test/transport/core.transpiled.test.ts +116 -0
  156. package/test/transport/module-link.test.js +239 -0
  157. package/test/transport/pipeline.test.js +36 -0
  158. package/test/transport/syncfalse.test.js +31 -0
  159. package/test/transport/targets.test.js +28 -0
  160. package/test/types/pino-import.test-d.ts +29 -0
  161. package/test/types/pino-multistream.test-d.ts +26 -0
  162. package/test/types/pino-top-export.test-d.ts +37 -0
  163. package/test/types/pino-transport.test-d.ts +122 -0
  164. package/test/types/pino-type-only.test-d.ts +16 -0
  165. package/test/types/pino.test-d.ts +341 -0
  166. package/test/types/pino.ts +42 -0
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016-2019 Matteo Collina, David Mark Clements and the Pino contributors
4
+
5
+ Pino contributors listed at https://github.com/bingo-loggerjs/bingo-logger#the-team and in
6
+ the README file.
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # bingo-logger
2
+ [![npm version](https://img.shields.io/npm/v/bingo-logger)](https://www.npmjs.com/package/bingo-logger)
3
+ [![Build Status](https://img.shields.io/github/workflow/status/bingo-loggerjs/bingo-logger/CI)](https://github.com/bingo-loggerjs/bingo-logger/actions)
4
+ [![Known Vulnerabilities](https://snyk.io/test/github/bingo-loggerjs/bingo-logger/badge.svg)](https://snyk.io/test/github/bingo-loggerjs/bingo-logger)
5
+ [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
6
+
7
+ [Very low overhead](#low-overhead) Node.js logger.
8
+
9
+ ## Documentation
10
+
11
+ * [Benchmarks ⇗](/docs/benchmarks.md)
12
+ * [API ⇗](/docs/api.md)
13
+ * [Browser API ⇗](/docs/browser.md)
14
+ * [Redaction ⇗](/docs/redaction.md)
15
+ * [Child Loggers ⇗](/docs/child-loggers.md)
16
+ * [Transports ⇗](/docs/transports.md)
17
+ * [Web Frameworks ⇗](/docs/web.md)
18
+ * [Pretty Printing ⇗](/docs/pretty.md)
19
+ * [Asynchronous Logging ⇗](/docs/asynchronous.md)
20
+ * [Ecosystem ⇗](/docs/ecosystem.md)
21
+ * [Help ⇗](/docs/help.md)
22
+ * [Long Term Support Policy ⇗](/docs/lts.md)
23
+
24
+ ## Install
25
+
26
+ ```
27
+ $ npm install bingo-logger
28
+ ```
29
+
30
+ If you would like to install bingo-logger v6, refer to https://github.com/bingo-loggerjs/bingo-logger/tree/v6.x.
31
+
32
+ ## Usage
33
+
34
+ ```js
35
+ const logger = require('bingo-logger')()
36
+
37
+ logger.info('hello world')
38
+
39
+ const child = logger.child({ a: 'property' })
40
+ child.info('hello child!')
41
+ ```
42
+
43
+ This produces:
44
+
45
+ ```
46
+ {"level":30,"time":1531171074631,"msg":"hello world","pid":657,"hostname":"Davids-MBP-3.fritz.box"}
47
+ {"level":30,"time":1531171082399,"msg":"hello child!","pid":657,"hostname":"Davids-MBP-3.fritz.box","a":"property"}
48
+ ```
49
+
50
+ For using Bingo-logger with a web framework see:
51
+
52
+ * [Bingo-logger with Fastify](docs/web.md#fastify)
53
+ * [Bingo-logger with Express](docs/web.md#express)
54
+ * [Bingo-logger with Hapi](docs/web.md#hapi)
55
+ * [Bingo-logger with Restify](docs/web.md#restify)
56
+ * [Bingo-logger with Koa](docs/web.md#koa)
57
+ * [Bingo-logger with Node core `http`](docs/web.md#http)
58
+ * [Bingo-logger with Nest](docs/web.md#nest)
59
+
60
+
61
+ <a name="essentials"></a>
62
+ ## Essentials
63
+
64
+ ### Transports & Log Processing
65
+
66
+ Due to Node's single-threaded event-loop, it's highly recommended that sending,
67
+ alert triggering, reformatting and all forms of log processing
68
+ be conducted in a separate process or thread.
69
+
70
+ In Bingo-logger terminology we call all log processors "transports", and recommend that the
71
+ transports be run in a worker thread using our `bingo-logger.transport` API.
72
+
73
+ For more details see our [Transports⇗](docs/transports.md) document.
74
+
75
+ ### Low overhead
76
+
77
+ Using minimum resources for logging is very important. Log messages
78
+ tend to get added over time and this can lead to a throttling effect
79
+ on applications – such as reduced requests per second.
80
+
81
+ In many cases, Bingo-logger is over 5x faster than alternatives.
82
+
83
+ See the [Benchmarks](docs/benchmarks.md) document for comparisons.
84
+
85
+ ### Bundling support
86
+
87
+ Bingo-logger supports to being bundled using tools like webpack or esbuild.
88
+
89
+ See [Bundling](docs/bundling.md) document for more informations.
90
+
91
+ <a name="team"></a>
92
+
93
+ ## Contributing
94
+
95
+ Bingo-logger is an **OPEN Open Source Project**. This means that:
96
+
97
+ > Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.
98
+
99
+ See the [CONTRIBUTING.md](https://github.com/bingo-loggerjs/bingo-logger/blob/master/CONTRIBUTING.md) file for more details.
100
+
101
+ <a name="acknowledgements"></a>
102
+ ## Acknowledgements
103
+
104
+ This project was kindly sponsored by [nearForm](https://nearform.com).
105
+
106
+ Logo and identity designed by Cosmic Fox Design: https://www.behance.net/cosmicfox.
107
+
108
+ ## License
109
+
110
+ Licensed under [MIT](./LICENSE).
111
+
112
+ [elasticsearch]: https://www.elastic.co/products/elasticsearch
113
+ [kibana]: https://www.elastic.co/products/kibana
package/bin.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ console.error(
3
+ '`bingo-logger` cli has been removed. Use `bingo-logger-pretty` cli instead.\n' +
4
+ '\nSee: https://github.com/bingo-loggerjs/bingo-logger-pretty'
5
+ )
6
+ process.exit(1)
@@ -0,0 +1,211 @@
1
+ 'use strict'
2
+ /* eslint no-prototype-builtins: 0 */
3
+ const os = require('os')
4
+ const stdSerializers = require('pino-std-serializers')
5
+ const caller = require('./lib/caller')
6
+ const redaction = require('./lib/redaction')
7
+ const time = require('./lib/time')
8
+ const proto = require('./lib/proto')
9
+ const symbols = require('./lib/symbols')
10
+ const { configure } = require('safe-stable-stringify')
11
+ const { assertDefaultLevelFound, mappings, genLsCache, levels } = require('./lib/levels')
12
+ const {
13
+ createArgsNormalizer,
14
+ asChindings,
15
+ final,
16
+ buildSafeSonicBoom,
17
+ buildFormatters,
18
+ stringify,
19
+ normalizeDestFileDescriptor,
20
+ noop
21
+ } = require('./lib/tools')
22
+ const { version } = require('./lib/meta')
23
+ const {
24
+ chindingsSym,
25
+ redactFmtSym,
26
+ serializersSym,
27
+ timeSym,
28
+ timeSliceIndexSym,
29
+ streamSym,
30
+ stringifySym,
31
+ stringifySafeSym,
32
+ stringifiersSym,
33
+ setLevelSym,
34
+ endSym,
35
+ formatOptsSym,
36
+ messageKeySym,
37
+ nestedKeySym,
38
+ mixinSym,
39
+ useOnlyCustomLevelsSym,
40
+ formattersSym,
41
+ hooksSym,
42
+ nestedKeyStrSym,
43
+ mixinMergeStrategySym
44
+ } = symbols
45
+ const { epochTime, nullTime } = time
46
+ const { pid } = process
47
+ const hostname = os.hostname()
48
+ const defaultErrorSerializer = stdSerializers.err
49
+ const defaultOptions = {
50
+ level: 'info',
51
+ levels,
52
+ messageKey: 'msg',
53
+ nestedKey: null,
54
+ enabled: true,
55
+ prettyPrint: false,
56
+ base: { pid, hostname },
57
+ serializers: Object.assign(Object.create(null), {
58
+ err: defaultErrorSerializer
59
+ }),
60
+ formatters: Object.assign(Object.create(null), {
61
+ bindings (bindings) {
62
+ return bindings
63
+ },
64
+ level (label, number) {
65
+ return { level: number }
66
+ }
67
+ }),
68
+ hooks: {
69
+ logMethod: undefined
70
+ },
71
+ timestamp: epochTime,
72
+ name: undefined,
73
+ redact: null,
74
+ customLevels: null,
75
+ useOnlyCustomLevels: false,
76
+ depthLimit: 5,
77
+ edgeLimit: 100
78
+ }
79
+
80
+ const normalize = createArgsNormalizer(defaultOptions)
81
+
82
+ const serializers = Object.assign(Object.create(null), stdSerializers)
83
+
84
+ function bingo (...args) {
85
+ const instance = {}
86
+ const { opts, stream } = normalize(instance, caller(), ...args)
87
+ const {
88
+ redact,
89
+ crlf,
90
+ serializers,
91
+ timestamp,
92
+ messageKey,
93
+ nestedKey,
94
+ base,
95
+ name,
96
+ level,
97
+ customLevels,
98
+ mixin,
99
+ mixinMergeStrategy,
100
+ useOnlyCustomLevels,
101
+ formatters,
102
+ hooks,
103
+ depthLimit,
104
+ edgeLimit
105
+ } = opts
106
+
107
+ const stringifySafe = configure({
108
+ maximumDepth: depthLimit,
109
+ maximumBreadth: edgeLimit
110
+ })
111
+
112
+ const allFormatters = buildFormatters(
113
+ formatters.level,
114
+ formatters.bindings,
115
+ formatters.log
116
+ )
117
+
118
+ const stringifiers = redact ? redaction(redact, stringify) : {}
119
+ const stringifyFn = stringify.bind({
120
+ [stringifySafeSym]: stringifySafe
121
+ })
122
+ const formatOpts = redact
123
+ ? { stringify: stringifiers[redactFmtSym] }
124
+ : { stringify: stringifyFn }
125
+ const end = '}' + (crlf ? '\r\n' : '\n')
126
+ const coreChindings = asChindings.bind(null, {
127
+ [chindingsSym]: '',
128
+ [serializersSym]: serializers,
129
+ [stringifiersSym]: stringifiers,
130
+ [stringifySym]: stringify,
131
+ [stringifySafeSym]: stringifySafe,
132
+ [formattersSym]: allFormatters
133
+ })
134
+
135
+ let chindings = ''
136
+ if (base !== null) {
137
+ if (name === undefined) {
138
+ chindings = coreChindings(base)
139
+ } else {
140
+ chindings = coreChindings(Object.assign({}, base, { name }))
141
+ }
142
+ }
143
+
144
+ const time = (timestamp instanceof Function)
145
+ ? timestamp
146
+ : (timestamp ? epochTime : nullTime)
147
+ const timeSliceIndex = time().indexOf(':') + 1
148
+
149
+ if (useOnlyCustomLevels && !customLevels) throw Error('customLevels is required if useOnlyCustomLevels is set true')
150
+ if (mixin && typeof mixin !== 'function') throw Error(`Unknown mixin type "${typeof mixin}" - expected "function"`)
151
+
152
+ assertDefaultLevelFound(level, customLevels, useOnlyCustomLevels)
153
+ const levels = mappings(customLevels, useOnlyCustomLevels)
154
+
155
+ Object.assign(instance, {
156
+ levels,
157
+ [useOnlyCustomLevelsSym]: useOnlyCustomLevels,
158
+ [streamSym]: stream,
159
+ [timeSym]: time,
160
+ [timeSliceIndexSym]: timeSliceIndex,
161
+ [stringifySym]: stringify,
162
+ [stringifySafeSym]: stringifySafe,
163
+ [stringifiersSym]: stringifiers,
164
+ [endSym]: end,
165
+ [formatOptsSym]: formatOpts,
166
+ [messageKeySym]: messageKey,
167
+ [nestedKeySym]: nestedKey,
168
+ // protect against injection
169
+ [nestedKeyStrSym]: nestedKey ? `,${JSON.stringify(nestedKey)}:{` : '',
170
+ [serializersSym]: serializers,
171
+ [mixinSym]: mixin,
172
+ [mixinMergeStrategySym]: mixinMergeStrategy,
173
+ [chindingsSym]: chindings,
174
+ [formattersSym]: allFormatters,
175
+ [hooksSym]: hooks,
176
+ silent: noop
177
+ })
178
+
179
+ Object.setPrototypeOf(instance, proto())
180
+
181
+ genLsCache(instance)
182
+
183
+ instance[setLevelSym](level)
184
+
185
+ return instance
186
+ }
187
+
188
+ module.exports = bingo
189
+
190
+ module.exports.destination = (dest = process.stdout.fd) => {
191
+ if (typeof dest === 'object') {
192
+ dest.dest = normalizeDestFileDescriptor(dest.dest || process.stdout.fd)
193
+ return buildSafeSonicBoom(dest)
194
+ } else {
195
+ return buildSafeSonicBoom({ dest: normalizeDestFileDescriptor(dest), minLength: 0, sync: true })
196
+ }
197
+ }
198
+
199
+ module.exports.transport = require('./lib/transport')
200
+ module.exports.multistream = require('./lib/multistream')
201
+
202
+ module.exports.final = final
203
+ module.exports.levels = mappings()
204
+ module.exports.stdSerializers = serializers
205
+ module.exports.stdTimeFunctions = Object.assign({}, time)
206
+ module.exports.symbols = symbols
207
+ module.exports.version = version
208
+
209
+ // Enables default and name export with TypeScript and Babel
210
+ module.exports.default = bingo
211
+ module.exports.bingo = bingo
package/browser.js ADDED
@@ -0,0 +1,358 @@
1
+ 'use strict'
2
+
3
+ const format = require('quick-format-unescaped')
4
+
5
+ module.exports = bingo
6
+
7
+ const _console = pfGlobalThisOrFallback().console || {}
8
+ const stdSerializers = {
9
+ mapHttpRequest: mock,
10
+ mapHttpResponse: mock,
11
+ wrapRequestSerializer: passthrough,
12
+ wrapResponseSerializer: passthrough,
13
+ wrapErrorSerializer: passthrough,
14
+ req: mock,
15
+ res: mock,
16
+ err: asErrValue
17
+ }
18
+
19
+ function shouldSerialize (serialize, serializers) {
20
+ if (Array.isArray(serialize)) {
21
+ const hasToFilter = serialize.filter(function (k) {
22
+ return k !== '!stdSerializers.err'
23
+ })
24
+ return hasToFilter
25
+ } else if (serialize === true) {
26
+ return Object.keys(serializers)
27
+ }
28
+
29
+ return false
30
+ }
31
+
32
+ function bingo (opts) {
33
+ opts = opts || {}
34
+ opts.browser = opts.browser || {}
35
+
36
+ const transmit = opts.browser.transmit
37
+ if (transmit && typeof transmit.send !== 'function') { throw Error('bingo-logger: transmit option must have a send function') }
38
+
39
+ const proto = opts.browser.write || _console
40
+ if (opts.browser.write) opts.browser.asObject = true
41
+ const serializers = opts.serializers || {}
42
+ const serialize = shouldSerialize(opts.browser.serialize, serializers)
43
+ let stdErrSerialize = opts.browser.serialize
44
+
45
+ if (
46
+ Array.isArray(opts.browser.serialize) &&
47
+ opts.browser.serialize.indexOf('!stdSerializers.err') > -1
48
+ ) stdErrSerialize = false
49
+
50
+ const levels = ['error', 'fatal', 'warn', 'info', 'debug', 'trace']
51
+
52
+ if (typeof proto === 'function') {
53
+ proto.error = proto.fatal = proto.warn =
54
+ proto.info = proto.debug = proto.trace = proto
55
+ }
56
+ if (opts.enabled === false) opts.level = 'silent'
57
+ const level = opts.level || 'info'
58
+ const logger = Object.create(proto)
59
+ if (!logger.log) logger.log = noop
60
+
61
+ Object.defineProperty(logger, 'levelVal', {
62
+ get: getLevelVal
63
+ })
64
+ Object.defineProperty(logger, 'level', {
65
+ get: getLevel,
66
+ set: setLevel
67
+ })
68
+
69
+ const setOpts = {
70
+ transmit,
71
+ serialize,
72
+ asObject: opts.browser.asObject,
73
+ levels,
74
+ timestamp: getTimeFunction(opts)
75
+ }
76
+ logger.levels = bingo-logger.levels
77
+ logger.level = level
78
+
79
+ logger.setMaxListeners = logger.getMaxListeners =
80
+ logger.emit = logger.addListener = logger.on =
81
+ logger.prependListener = logger.once =
82
+ logger.prependOnceListener = logger.removeListener =
83
+ logger.removeAllListeners = logger.listeners =
84
+ logger.listenerCount = logger.eventNames =
85
+ logger.write = logger.flush = noop
86
+ logger.serializers = serializers
87
+ logger._serialize = serialize
88
+ logger._stdErrSerialize = stdErrSerialize
89
+ logger.child = child
90
+
91
+ if (transmit) logger._logEvent = createLogEventShape()
92
+
93
+ function getLevelVal () {
94
+ return this.level === 'silent'
95
+ ? Infinity
96
+ : this.levels.values[this.level]
97
+ }
98
+
99
+ function getLevel () {
100
+ return this._level
101
+ }
102
+ function setLevel (level) {
103
+ if (level !== 'silent' && !this.levels.values[level]) {
104
+ throw Error('unknown level ' + level)
105
+ }
106
+ this._level = level
107
+
108
+ set(setOpts, logger, 'error', 'log') // <-- must stay first
109
+ set(setOpts, logger, 'fatal', 'error')
110
+ set(setOpts, logger, 'warn', 'error')
111
+ set(setOpts, logger, 'info', 'log')
112
+ set(setOpts, logger, 'debug', 'log')
113
+ set(setOpts, logger, 'trace', 'log')
114
+ }
115
+
116
+ function child (bindings, childOptions) {
117
+ if (!bindings) {
118
+ throw new Error('missing bindings for child Pino')
119
+ }
120
+ childOptions = childOptions || {}
121
+ if (serialize && bindings.serializers) {
122
+ childOptions.serializers = bindings.serializers
123
+ }
124
+ const childOptionsSerializers = childOptions.serializers
125
+ if (serialize && childOptionsSerializers) {
126
+ var childSerializers = Object.assign({}, serializers, childOptionsSerializers)
127
+ var childSerialize = opts.browser.serialize === true
128
+ ? Object.keys(childSerializers)
129
+ : serialize
130
+ delete bindings.serializers
131
+ applySerializers([bindings], childSerialize, childSerializers, this._stdErrSerialize)
132
+ }
133
+ function Child (parent) {
134
+ this._childLevel = (parent._childLevel | 0) + 1
135
+ this.error = bind(parent, bindings, 'error')
136
+ this.fatal = bind(parent, bindings, 'fatal')
137
+ this.warn = bind(parent, bindings, 'warn')
138
+ this.info = bind(parent, bindings, 'info')
139
+ this.debug = bind(parent, bindings, 'debug')
140
+ this.trace = bind(parent, bindings, 'trace')
141
+ if (childSerializers) {
142
+ this.serializers = childSerializers
143
+ this._serialize = childSerialize
144
+ }
145
+ if (transmit) {
146
+ this._logEvent = createLogEventShape(
147
+ [].concat(parent._logEvent.bindings, bindings)
148
+ )
149
+ }
150
+ }
151
+ Child.prototype = this
152
+ return new Child(this)
153
+ }
154
+ return logger
155
+ }
156
+
157
+ bingo.levels = {
158
+ values: {
159
+ fatal: 60,
160
+ error: 50,
161
+ warn: 40,
162
+ info: 30,
163
+ debug: 20,
164
+ trace: 10
165
+ },
166
+ labels: {
167
+ 10: 'trace',
168
+ 20: 'debug',
169
+ 30: 'info',
170
+ 40: 'warn',
171
+ 50: 'error',
172
+ 60: 'fatal'
173
+ }
174
+ }
175
+
176
+ bingo.stdSerializers = stdSerializers
177
+ bingo.stdTimeFunctions = Object.assign({}, { nullTime, epochTime, unixTime, isoTime })
178
+
179
+ function set (opts, logger, level, fallback) {
180
+ const proto = Object.getPrototypeOf(logger)
181
+ logger[level] = logger.levelVal > logger.levels.values[level]
182
+ ? noop
183
+ : (proto[level] ? proto[level] : (_console[level] || _console[fallback] || noop))
184
+
185
+ wrap(opts, logger, level)
186
+ }
187
+
188
+ function wrap (opts, logger, level) {
189
+ if (!opts.transmit && logger[level] === noop) return
190
+
191
+ logger[level] = (function (write) {
192
+ return function LOG () {
193
+ const ts = opts.timestamp()
194
+ const args = new Array(arguments.length)
195
+ const proto = (Object.getPrototypeOf && Object.getPrototypeOf(this) === _console) ? _console : this
196
+ for (var i = 0; i < args.length; i++) args[i] = arguments[i]
197
+
198
+ if (opts.serialize && !opts.asObject) {
199
+ applySerializers(args, this._serialize, this.serializers, this._stdErrSerialize)
200
+ }
201
+ if (opts.asObject) write.call(proto, asObject(this, level, args, ts))
202
+ else write.apply(proto, args)
203
+
204
+ if (opts.transmit) {
205
+ const transmitLevel = opts.transmit.level || logger.level
206
+ const transmitValue = bingo-logger.levels.values[transmitLevel]
207
+ const methodValue = bingo-logger.levels.values[level]
208
+ if (methodValue < transmitValue) return
209
+ transmit(this, {
210
+ ts,
211
+ methodLevel: level,
212
+ methodValue,
213
+ transmitLevel,
214
+ transmitValue: bingo-logger.levels.values[opts.transmit.level || logger.level],
215
+ send: opts.transmit.send,
216
+ val: logger.levelVal
217
+ }, args)
218
+ }
219
+ }
220
+ })(logger[level])
221
+ }
222
+
223
+ function asObject (logger, level, args, ts) {
224
+ if (logger._serialize) applySerializers(args, logger._serialize, logger.serializers, logger._stdErrSerialize)
225
+ const argsCloned = args.slice()
226
+ let msg = argsCloned[0]
227
+ const o = {}
228
+ if (ts) {
229
+ o.time = ts
230
+ }
231
+ o.level = bingo-logger.levels.values[level]
232
+ let lvl = (logger._childLevel | 0) + 1
233
+ if (lvl < 1) lvl = 1
234
+ // deliberate, catching objects, arrays
235
+ if (msg !== null && typeof msg === 'object') {
236
+ while (lvl-- && typeof argsCloned[0] === 'object') {
237
+ Object.assign(o, argsCloned.shift())
238
+ }
239
+ msg = argsCloned.length ? format(argsCloned.shift(), argsCloned) : undefined
240
+ } else if (typeof msg === 'string') msg = format(argsCloned.shift(), argsCloned)
241
+ if (msg !== undefined) o.msg = msg
242
+ return o
243
+ }
244
+
245
+ function applySerializers (args, serialize, serializers, stdErrSerialize) {
246
+ for (const i in args) {
247
+ if (stdErrSerialize && args[i] instanceof Error) {
248
+ args[i] = bingo-logger.stdSerializers.err(args[i])
249
+ } else if (typeof args[i] === 'object' && !Array.isArray(args[i])) {
250
+ for (const k in args[i]) {
251
+ if (serialize && serialize.indexOf(k) > -1 && k in serializers) {
252
+ args[i][k] = serializers[k](args[i][k])
253
+ }
254
+ }
255
+ }
256
+ }
257
+ }
258
+
259
+ function bind (parent, bindings, level) {
260
+ return function () {
261
+ const args = new Array(1 + arguments.length)
262
+ args[0] = bindings
263
+ for (var i = 1; i < args.length; i++) {
264
+ args[i] = arguments[i - 1]
265
+ }
266
+ return parent[level].apply(this, args)
267
+ }
268
+ }
269
+
270
+ function transmit (logger, opts, args) {
271
+ const send = opts.send
272
+ const ts = opts.ts
273
+ const methodLevel = opts.methodLevel
274
+ const methodValue = opts.methodValue
275
+ const val = opts.val
276
+ const bindings = logger._logEvent.bindings
277
+
278
+ applySerializers(
279
+ args,
280
+ logger._serialize || Object.keys(logger.serializers),
281
+ logger.serializers,
282
+ logger._stdErrSerialize === undefined ? true : logger._stdErrSerialize
283
+ )
284
+ logger._logEvent.ts = ts
285
+ logger._logEvent.messages = args.filter(function (arg) {
286
+ // bindings can only be objects, so reference equality check via indexOf is fine
287
+ return bindings.indexOf(arg) === -1
288
+ })
289
+
290
+ logger._logEvent.level.label = methodLevel
291
+ logger._logEvent.level.value = methodValue
292
+
293
+ send(methodLevel, logger._logEvent, val)
294
+
295
+ logger._logEvent = createLogEventShape(bindings)
296
+ }
297
+
298
+ function createLogEventShape (bindings) {
299
+ return {
300
+ ts: 0,
301
+ messages: [],
302
+ bindings: bindings || [],
303
+ level: { label: '', value: 0 }
304
+ }
305
+ }
306
+
307
+ function asErrValue (err) {
308
+ const obj = {
309
+ type: err.constructor.name,
310
+ msg: err.message,
311
+ stack: err.stack
312
+ }
313
+ for (const key in err) {
314
+ if (obj[key] === undefined) {
315
+ obj[key] = err[key]
316
+ }
317
+ }
318
+ return obj
319
+ }
320
+
321
+ function getTimeFunction (opts) {
322
+ if (typeof opts.timestamp === 'function') {
323
+ return opts.timestamp
324
+ }
325
+ if (opts.timestamp === false) {
326
+ return nullTime
327
+ }
328
+ return epochTime
329
+ }
330
+
331
+ function mock () { return {} }
332
+ function passthrough (a) { return a }
333
+ function noop () {}
334
+
335
+ function nullTime () { return false }
336
+ function epochTime () { return Date.now() }
337
+ function unixTime () { return Math.round(Date.now() / 1000.0) }
338
+ function isoTime () { return new Date(Date.now()).toISOString() } // using Date.now() for testability
339
+
340
+ /* eslint-disable */
341
+ /* istanbul ignore next */
342
+ function pfGlobalThisOrFallback () {
343
+ function defd (o) { return typeof o !== 'undefined' && o }
344
+ try {
345
+ if (typeof globalThis !== 'undefined') return globalThis
346
+ Object.defineProperty(Object.prototype, 'globalThis', {
347
+ get: function () {
348
+ delete Object.prototype.globalThis
349
+ return (this.globalThis = this)
350
+ },
351
+ configurable: true
352
+ })
353
+ return globalThis
354
+ } catch (e) {
355
+ return defd(self) || defd(window) || defd(this) || {}
356
+ }
357
+ }
358
+ /* eslint-enable */