effect 3.4.9 → 3.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RcMap/package.json +6 -0
- package/RcRef/package.json +6 -0
- package/dist/cjs/Cause.js +22 -1
- package/dist/cjs/Cause.js.map +1 -1
- package/dist/cjs/Channel.js.map +1 -1
- package/dist/cjs/Config.js.map +1 -1
- package/dist/cjs/Console.js.map +1 -1
- package/dist/cjs/Data.js +3 -1
- package/dist/cjs/Data.js.map +1 -1
- package/dist/cjs/Duration.js +23 -2
- package/dist/cjs/Duration.js.map +1 -1
- package/dist/cjs/Effect.js +78 -15
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/Logger.js +234 -13
- package/dist/cjs/Logger.js.map +1 -1
- package/dist/cjs/PubSub.js.map +1 -1
- package/dist/cjs/Random.js +24 -1
- package/dist/cjs/Random.js.map +1 -1
- package/dist/cjs/RcMap.js +52 -0
- package/dist/cjs/RcMap.js.map +1 -0
- package/dist/cjs/RcRef.js +51 -0
- package/dist/cjs/RcRef.js.map +1 -0
- package/dist/cjs/Stream.js +29 -2
- package/dist/cjs/Stream.js.map +1 -1
- package/dist/cjs/index.js +6 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internal/cause.js +21 -5
- package/dist/cjs/internal/cause.js.map +1 -1
- package/dist/cjs/internal/channel/channelExecutor.js.map +1 -1
- package/dist/cjs/internal/channel.js.map +1 -1
- package/dist/cjs/internal/core-effect.js +0 -5
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/core.js +15 -10
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/defaultServices.js +1 -1
- package/dist/cjs/internal/defaultServices.js.map +1 -1
- package/dist/cjs/internal/fiberRuntime.js +3 -1
- package/dist/cjs/internal/fiberRuntime.js.map +1 -1
- package/dist/cjs/internal/logger.js +129 -27
- package/dist/cjs/internal/logger.js.map +1 -1
- package/dist/cjs/internal/pubsub.js +216 -36
- package/dist/cjs/internal/pubsub.js.map +1 -1
- package/dist/cjs/internal/random.js +2 -1
- package/dist/cjs/internal/random.js.map +1 -1
- package/dist/cjs/internal/rcMap.js +129 -0
- package/dist/cjs/internal/rcMap.js.map +1 -0
- package/dist/cjs/internal/rcRef.js +122 -0
- package/dist/cjs/internal/rcRef.js.map +1 -0
- package/dist/cjs/internal/stream.js +57 -11
- package/dist/cjs/internal/stream.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Cause.d.ts +40 -1
- package/dist/dts/Cause.d.ts.map +1 -1
- package/dist/dts/Channel.d.ts +3 -3
- package/dist/dts/Channel.d.ts.map +1 -1
- package/dist/dts/Config.d.ts +5 -0
- package/dist/dts/Config.d.ts.map +1 -1
- package/dist/dts/Console.d.ts +2 -4
- package/dist/dts/Console.d.ts.map +1 -1
- package/dist/dts/Duration.d.ts +5 -0
- package/dist/dts/Duration.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts +78 -15
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/Logger.d.ts +238 -12
- package/dist/dts/Logger.d.ts.map +1 -1
- package/dist/dts/PubSub.d.ts +15 -4
- package/dist/dts/PubSub.d.ts.map +1 -1
- package/dist/dts/Random.d.ts +23 -0
- package/dist/dts/Random.d.ts.map +1 -1
- package/dist/dts/RcMap.d.ts +93 -0
- package/dist/dts/RcMap.d.ts.map +1 -0
- package/dist/dts/RcRef.d.ts +83 -0
- package/dist/dts/RcRef.d.ts.map +1 -0
- package/dist/dts/Stream.d.ts +64 -26
- package/dist/dts/Stream.d.ts.map +1 -1
- package/dist/dts/index.d.ts +8 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/internal/core-effect.d.ts.map +1 -1
- package/dist/dts/internal/fiberRuntime.d.ts.map +1 -1
- package/dist/dts/internal/logger.d.ts.map +1 -1
- package/dist/dts/internal/random.d.ts +1 -1
- package/dist/dts/internal/random.d.ts.map +1 -1
- package/dist/dts/internal/rcMap.d.ts +2 -0
- package/dist/dts/internal/rcMap.d.ts.map +1 -0
- package/dist/dts/internal/rcRef.d.ts +2 -0
- package/dist/dts/internal/rcRef.d.ts.map +1 -0
- package/dist/dts/internal/stream.d.ts +1 -0
- package/dist/dts/internal/stream.d.ts.map +1 -1
- package/dist/esm/Cause.js +21 -0
- package/dist/esm/Cause.js.map +1 -1
- package/dist/esm/Channel.js.map +1 -1
- package/dist/esm/Config.js.map +1 -1
- package/dist/esm/Console.js.map +1 -1
- package/dist/esm/Data.js +3 -1
- package/dist/esm/Data.js.map +1 -1
- package/dist/esm/Duration.js +20 -0
- package/dist/esm/Duration.js.map +1 -1
- package/dist/esm/Effect.js +78 -15
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/Logger.js +233 -12
- package/dist/esm/Logger.js.map +1 -1
- package/dist/esm/PubSub.js.map +1 -1
- package/dist/esm/Random.js +23 -0
- package/dist/esm/Random.js.map +1 -1
- package/dist/esm/RcMap.js +44 -0
- package/dist/esm/RcMap.js.map +1 -0
- package/dist/esm/RcRef.js +43 -0
- package/dist/esm/RcRef.js.map +1 -0
- package/dist/esm/Stream.js +27 -0
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/cause.js +21 -5
- package/dist/esm/internal/cause.js.map +1 -1
- package/dist/esm/internal/channel/channelExecutor.js.map +1 -1
- package/dist/esm/internal/channel.js.map +1 -1
- package/dist/esm/internal/core-effect.js +0 -5
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/core.js +11 -7
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/defaultServices.js +1 -1
- package/dist/esm/internal/defaultServices.js.map +1 -1
- package/dist/esm/internal/fiberRuntime.js +2 -0
- package/dist/esm/internal/fiberRuntime.js.map +1 -1
- package/dist/esm/internal/logger.js +127 -26
- package/dist/esm/internal/logger.js.map +1 -1
- package/dist/esm/internal/pubsub.js +216 -36
- package/dist/esm/internal/pubsub.js.map +1 -1
- package/dist/esm/internal/random.js +2 -1
- package/dist/esm/internal/random.js.map +1 -1
- package/dist/esm/internal/rcMap.js +120 -0
- package/dist/esm/internal/rcMap.js.map +1 -0
- package/dist/esm/internal/rcRef.js +112 -0
- package/dist/esm/internal/rcRef.js.map +1 -0
- package/dist/esm/internal/stream.js +53 -8
- package/dist/esm/internal/stream.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +17 -1
- package/src/Cause.ts +47 -1
- package/src/Channel.ts +3 -3
- package/src/Config.ts +6 -0
- package/src/Console.ts +2 -4
- package/src/Data.ts +1 -1
- package/src/Duration.ts +18 -0
- package/src/Effect.ts +78 -15
- package/src/Logger.ts +242 -12
- package/src/PubSub.ts +11 -4
- package/src/Random.ts +24 -0
- package/src/RcMap.ts +103 -0
- package/src/RcRef.ts +91 -0
- package/src/Stream.ts +83 -26
- package/src/index.ts +10 -0
- package/src/internal/cause.ts +26 -5
- package/src/internal/channel/channelExecutor.ts +1 -1
- package/src/internal/channel.ts +4 -3
- package/src/internal/core-effect.ts +0 -5
- package/src/internal/core.ts +19 -9
- package/src/internal/defaultServices.ts +1 -1
- package/src/internal/fiberRuntime.ts +6 -0
- package/src/internal/logger.ts +135 -27
- package/src/internal/pubsub.ts +249 -58
- package/src/internal/random.ts +2 -1
- package/src/internal/rcMap.ts +213 -0
- package/src/internal/rcRef.ts +172 -0
- package/src/internal/stream.ts +325 -111
- package/src/internal/version.ts +1 -1
package/src/internal/core.ts
CHANGED
|
@@ -2174,23 +2174,19 @@ export const causeSquashWith = dual<
|
|
|
2174
2174
|
// -----------------------------------------------------------------------------
|
|
2175
2175
|
|
|
2176
2176
|
/** @internal */
|
|
2177
|
-
export const YieldableError: new(message?: string) => Cause.YieldableError = (function() {
|
|
2177
|
+
export const YieldableError: new(message?: string, options?: ErrorOptions) => Cause.YieldableError = (function() {
|
|
2178
2178
|
class YieldableError extends globalThis.Error {
|
|
2179
2179
|
commit() {
|
|
2180
2180
|
return fail(this)
|
|
2181
2181
|
}
|
|
2182
|
-
toString() {
|
|
2183
|
-
return this.message ? `${this.name}: ${this.message}` : this.name
|
|
2184
|
-
}
|
|
2185
2182
|
toJSON() {
|
|
2186
2183
|
return { ...this }
|
|
2187
2184
|
}
|
|
2188
|
-
[NodeInspectSymbol]()
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
return `${this.toString()}\n${stack.split("\n").slice(1).join("\n")}`
|
|
2185
|
+
[NodeInspectSymbol]() {
|
|
2186
|
+
if (this.toString !== globalThis.Error.prototype.toString) {
|
|
2187
|
+
return this.stack ? `${this.toString()}\n${this.stack.split("\n").slice(1).join("\n")}` : this.toString()
|
|
2192
2188
|
}
|
|
2193
|
-
return this
|
|
2189
|
+
return this
|
|
2194
2190
|
}
|
|
2195
2191
|
}
|
|
2196
2192
|
Object.assign(YieldableError.prototype, StructuralCommitPrototype)
|
|
@@ -2274,6 +2270,20 @@ export const InvalidPubSubCapacityException = makeException<Cause.InvalidPubSubC
|
|
|
2274
2270
|
[InvalidPubSubCapacityExceptionTypeId]: InvalidPubSubCapacityExceptionTypeId
|
|
2275
2271
|
}, "InvalidPubSubCapacityException")
|
|
2276
2272
|
|
|
2273
|
+
/** @internal */
|
|
2274
|
+
export const ExceededCapacityExceptionTypeId: Cause.ExceededCapacityExceptionTypeId = Symbol.for(
|
|
2275
|
+
"effect/Cause/errors/ExceededCapacityException"
|
|
2276
|
+
) as Cause.ExceededCapacityExceptionTypeId
|
|
2277
|
+
|
|
2278
|
+
/** @internal */
|
|
2279
|
+
export const ExceededCapacityException = makeException<Cause.ExceededCapacityException>({
|
|
2280
|
+
[ExceededCapacityExceptionTypeId]: ExceededCapacityExceptionTypeId
|
|
2281
|
+
}, "ExceededCapacityException")
|
|
2282
|
+
|
|
2283
|
+
/** @internal */
|
|
2284
|
+
export const isExceededCapacityException = (u: unknown): u is Cause.ExceededCapacityException =>
|
|
2285
|
+
hasProperty(u, ExceededCapacityExceptionTypeId)
|
|
2286
|
+
|
|
2277
2287
|
/** @internal */
|
|
2278
2288
|
export const isInvalidCapacityError = (u: unknown): u is Cause.InvalidPubSubCapacityException =>
|
|
2279
2289
|
hasProperty(u, InvalidPubSubCapacityExceptionTypeId)
|
|
@@ -22,7 +22,7 @@ export const liveServices: Context.Context<DefaultServices.DefaultServices> = pi
|
|
|
22
22
|
Context.empty(),
|
|
23
23
|
Context.add(clock.clockTag, clock.make()),
|
|
24
24
|
Context.add(console_.consoleTag, console_.defaultConsole),
|
|
25
|
-
Context.add(random.randomTag, random.make(
|
|
25
|
+
Context.add(random.randomTag, random.make(Math.random())),
|
|
26
26
|
Context.add(configProvider.configProviderTag, configProvider.fromEnv()),
|
|
27
27
|
Context.add(tracer.tracerTag, tracer.nativeTracer)
|
|
28
28
|
)
|
|
@@ -1421,6 +1421,12 @@ export const logFmtLogger: Logger<unknown, void> = globalValue(
|
|
|
1421
1421
|
() => loggerWithConsoleLog(internalLogger.logfmtLogger)
|
|
1422
1422
|
)
|
|
1423
1423
|
|
|
1424
|
+
/** @internal */
|
|
1425
|
+
export const prettyLogger: Logger<unknown, void> = globalValue(
|
|
1426
|
+
Symbol.for("effect/Logger/prettyLogger"),
|
|
1427
|
+
() => internalLogger.prettyLogger()
|
|
1428
|
+
)
|
|
1429
|
+
|
|
1424
1430
|
/** @internal */
|
|
1425
1431
|
export const structuredLogger: Logger<unknown, void> = globalValue(
|
|
1426
1432
|
Symbol.for("effect/Logger/structuredLogger"),
|
package/src/internal/logger.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import * as Arr from "../Array.js"
|
|
2
|
+
import * as Context from "../Context.js"
|
|
3
|
+
import * as FiberRefs from "../FiberRefs.js"
|
|
1
4
|
import type { LazyArg } from "../Function.js"
|
|
2
5
|
import { constVoid, dual, pipe } from "../Function.js"
|
|
3
6
|
import * as HashMap from "../HashMap.js"
|
|
@@ -9,6 +12,8 @@ import * as LogSpan from "../LogSpan.js"
|
|
|
9
12
|
import * as Option from "../Option.js"
|
|
10
13
|
import { pipeArguments } from "../Pipeable.js"
|
|
11
14
|
import * as Cause from "./cause.js"
|
|
15
|
+
import * as defaultServices from "./defaultServices.js"
|
|
16
|
+
import { consoleTag } from "./defaultServices/console.js"
|
|
12
17
|
import * as _fiberId from "./fiberId.js"
|
|
13
18
|
|
|
14
19
|
/** @internal */
|
|
@@ -157,7 +162,7 @@ export const zipRight = dual<
|
|
|
157
162
|
>(2, (self, that) => map(zip(self, that), (tuple) => tuple[1]))
|
|
158
163
|
|
|
159
164
|
/** @internal */
|
|
160
|
-
export const stringLogger: Logger.Logger<unknown, string> = makeLogger
|
|
165
|
+
export const stringLogger: Logger.Logger<unknown, string> = makeLogger(
|
|
161
166
|
({ annotations, cause, date, fiberId, logLevel, message, spans }) => {
|
|
162
167
|
const nowMillis = date.getTime()
|
|
163
168
|
|
|
@@ -169,16 +174,9 @@ export const stringLogger: Logger.Logger<unknown, string> = makeLogger<unknown,
|
|
|
169
174
|
|
|
170
175
|
let output = outputArray.join(" ")
|
|
171
176
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (stringMessage.length > 0) {
|
|
176
|
-
output = output + " message="
|
|
177
|
-
output = appendQuoted(stringMessage, output)
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
} else {
|
|
181
|
-
const stringMessage = Inspectable.toStringUnknown(message)
|
|
177
|
+
const messageArr = Arr.ensure(message)
|
|
178
|
+
for (let i = 0; i < messageArr.length; i++) {
|
|
179
|
+
const stringMessage = Inspectable.toStringUnknown(messageArr[i])
|
|
182
180
|
if (stringMessage.length > 0) {
|
|
183
181
|
output = output + " message="
|
|
184
182
|
output = appendQuoted(stringMessage, output)
|
|
@@ -187,7 +185,7 @@ export const stringLogger: Logger.Logger<unknown, string> = makeLogger<unknown,
|
|
|
187
185
|
|
|
188
186
|
if (cause != null && cause._tag !== "Empty") {
|
|
189
187
|
output = output + " cause="
|
|
190
|
-
output = appendQuoted(Cause.pretty(cause), output)
|
|
188
|
+
output = appendQuoted(Cause.pretty(cause, { renderErrorCause: true }), output)
|
|
191
189
|
}
|
|
192
190
|
|
|
193
191
|
if (List.isCons(spans)) {
|
|
@@ -204,7 +202,7 @@ export const stringLogger: Logger.Logger<unknown, string> = makeLogger<unknown,
|
|
|
204
202
|
}
|
|
205
203
|
}
|
|
206
204
|
|
|
207
|
-
if (
|
|
205
|
+
if (HashMap.size(annotations) > 0) {
|
|
208
206
|
output = output + " "
|
|
209
207
|
|
|
210
208
|
let first = true
|
|
@@ -246,16 +244,9 @@ export const logfmtLogger = makeLogger<unknown, string>(
|
|
|
246
244
|
|
|
247
245
|
let output = outputArray.join(" ")
|
|
248
246
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
if (stringMessage.length > 0) {
|
|
253
|
-
output = output + " message="
|
|
254
|
-
output = appendQuotedLogfmt(stringMessage, output)
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
} else {
|
|
258
|
-
const stringMessage = Inspectable.toStringUnknown(message, 0)
|
|
247
|
+
const messageArr = Arr.ensure(message)
|
|
248
|
+
for (let i = 0; i < messageArr.length; i++) {
|
|
249
|
+
const stringMessage = Inspectable.toStringUnknown(messageArr[i], 0)
|
|
259
250
|
if (stringMessage.length > 0) {
|
|
260
251
|
output = output + " message="
|
|
261
252
|
output = appendQuotedLogfmt(stringMessage, output)
|
|
@@ -264,7 +255,7 @@ export const logfmtLogger = makeLogger<unknown, string>(
|
|
|
264
255
|
|
|
265
256
|
if (cause != null && cause._tag !== "Empty") {
|
|
266
257
|
output = output + " cause="
|
|
267
|
-
output = appendQuotedLogfmt(Cause.pretty(cause), output)
|
|
258
|
+
output = appendQuotedLogfmt(Cause.pretty(cause, { renderErrorCause: true }), output)
|
|
268
259
|
}
|
|
269
260
|
|
|
270
261
|
if (List.isCons(spans)) {
|
|
@@ -281,7 +272,7 @@ export const logfmtLogger = makeLogger<unknown, string>(
|
|
|
281
272
|
}
|
|
282
273
|
}
|
|
283
274
|
|
|
284
|
-
if (
|
|
275
|
+
if (HashMap.size(annotations) > 0) {
|
|
285
276
|
output = output + " "
|
|
286
277
|
|
|
287
278
|
let first = true
|
|
@@ -328,11 +319,12 @@ export const structuredLogger = makeLogger<unknown, {
|
|
|
328
319
|
}
|
|
329
320
|
}
|
|
330
321
|
|
|
322
|
+
const messageArr = Arr.ensure(message)
|
|
331
323
|
return {
|
|
332
|
-
message: structuredMessage(
|
|
324
|
+
message: messageArr.length === 1 ? structuredMessage(messageArr[0]) : messageArr.map(structuredMessage),
|
|
333
325
|
logLevel: logLevel.label,
|
|
334
326
|
timestamp: date.toISOString(),
|
|
335
|
-
cause: Cause.isEmpty(cause) ? undefined : Cause.pretty(cause),
|
|
327
|
+
cause: Cause.isEmpty(cause) ? undefined : Cause.pretty(cause, { renderErrorCause: true }),
|
|
336
328
|
annotations: annotationsObj,
|
|
337
329
|
spans: spansObj,
|
|
338
330
|
fiberId: _fiberId.threadName(fiberId)
|
|
@@ -376,3 +368,119 @@ const renderLogSpanLogfmt = (now: number) => (self: LogSpan.LogSpan): string =>
|
|
|
376
368
|
export const isLogger = (u: unknown): u is Logger.Logger<unknown, unknown> => {
|
|
377
369
|
return typeof u === "object" && u != null && LoggerTypeId in u
|
|
378
370
|
}
|
|
371
|
+
|
|
372
|
+
const withColor = (text: string, ...colors: ReadonlyArray<string>) => {
|
|
373
|
+
let out = ""
|
|
374
|
+
for (let i = 0; i < colors.length; i++) {
|
|
375
|
+
out += `\x1b[${colors[i]}m`
|
|
376
|
+
}
|
|
377
|
+
return out + text + "\x1b[0m"
|
|
378
|
+
}
|
|
379
|
+
const withColorNoop = (text: string, ..._colors: ReadonlyArray<string>) => text
|
|
380
|
+
const colors = {
|
|
381
|
+
bold: "1",
|
|
382
|
+
red: "31",
|
|
383
|
+
green: "32",
|
|
384
|
+
yellow: "33",
|
|
385
|
+
blue: "34",
|
|
386
|
+
cyan: "36",
|
|
387
|
+
white: "37",
|
|
388
|
+
gray: "90",
|
|
389
|
+
black: "30",
|
|
390
|
+
bgBrightRed: "101"
|
|
391
|
+
} as const
|
|
392
|
+
|
|
393
|
+
const logLevelColors: Record<LogLevel.LogLevel["_tag"], ReadonlyArray<string>> = {
|
|
394
|
+
None: [],
|
|
395
|
+
All: [],
|
|
396
|
+
Trace: [colors.gray],
|
|
397
|
+
Debug: [colors.blue],
|
|
398
|
+
Info: [colors.green],
|
|
399
|
+
Warning: [colors.yellow],
|
|
400
|
+
Error: [colors.red],
|
|
401
|
+
Fatal: [colors.bgBrightRed, colors.black]
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const defaultDateFormat = (date: Date): string =>
|
|
405
|
+
`${date.getHours().toString().padStart(2, "0")}:${date.getMinutes().toString().padStart(2, "0")}:${
|
|
406
|
+
date.getSeconds().toString().padStart(2, "0")
|
|
407
|
+
}.${date.getMilliseconds().toString().padStart(3, "0")}`
|
|
408
|
+
|
|
409
|
+
const processStdoutIsTTY = typeof process === "object" && "stdout" in process && process.stdout.isTTY === true
|
|
410
|
+
const processIsBun = typeof process === "object" && "isBun" in process && process.isBun === true
|
|
411
|
+
const hasWindow = typeof window === "object"
|
|
412
|
+
|
|
413
|
+
/** @internal */
|
|
414
|
+
export const prettyLogger = (options?: {
|
|
415
|
+
readonly colors?: "auto" | boolean | undefined
|
|
416
|
+
readonly stderr?: boolean | undefined
|
|
417
|
+
readonly formatDate?: ((date: Date) => string) | undefined
|
|
418
|
+
readonly mode?: "browser" | "tty" | "auto" | undefined
|
|
419
|
+
}) => {
|
|
420
|
+
const mode_ = options?.mode ?? "auto"
|
|
421
|
+
const mode = mode_ === "auto" ? (hasWindow ? "browser" : "tty") : mode_
|
|
422
|
+
const isBrowser = mode === "browser"
|
|
423
|
+
const showColors = typeof options?.colors === "boolean" ? options.colors : processStdoutIsTTY || isBrowser
|
|
424
|
+
const color = showColors ? withColor : withColorNoop
|
|
425
|
+
const formatDate = options?.formatDate ?? defaultDateFormat
|
|
426
|
+
|
|
427
|
+
return makeLogger<unknown, void>(
|
|
428
|
+
({ annotations, cause, context, date, fiberId, logLevel, message: message_, spans }) => {
|
|
429
|
+
const services = FiberRefs.getOrDefault(context, defaultServices.currentServices)
|
|
430
|
+
const console = Context.get(services, consoleTag).unsafe
|
|
431
|
+
const log = options?.stderr === true ? console.error : console.log
|
|
432
|
+
|
|
433
|
+
const message = Arr.ensure(message_)
|
|
434
|
+
|
|
435
|
+
let firstLine = color(`[${formatDate(date)}]`, colors.white)
|
|
436
|
+
+ ` ${color(logLevel.label, ...logLevelColors[logLevel._tag])}`
|
|
437
|
+
+ ` (${_fiberId.threadName(fiberId)})`
|
|
438
|
+
|
|
439
|
+
if (List.isCons(spans)) {
|
|
440
|
+
const now = date.getTime()
|
|
441
|
+
const render = renderLogSpanLogfmt(now)
|
|
442
|
+
for (const span of spans) {
|
|
443
|
+
firstLine += " " + render(span)
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
firstLine += ":"
|
|
448
|
+
let messageIndex = 0
|
|
449
|
+
if (message.length > 0) {
|
|
450
|
+
const firstMaybeString = structuredMessage(message[0])
|
|
451
|
+
if (typeof firstMaybeString === "string") {
|
|
452
|
+
firstLine += " " + color(firstMaybeString, colors.bold, colors.cyan)
|
|
453
|
+
messageIndex++
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if (isBrowser) {
|
|
458
|
+
console.groupCollapsed(firstLine)
|
|
459
|
+
} else {
|
|
460
|
+
log(firstLine)
|
|
461
|
+
if (!processIsBun) console.group()
|
|
462
|
+
}
|
|
463
|
+
if (!Cause.isEmpty(cause)) {
|
|
464
|
+
if (isBrowser) {
|
|
465
|
+
console.error(Cause.pretty(cause, { renderErrorCause: true }))
|
|
466
|
+
} else {
|
|
467
|
+
log(Cause.pretty(cause, { renderErrorCause: true }))
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
if (messageIndex < message.length) {
|
|
472
|
+
for (; messageIndex < message.length; messageIndex++) {
|
|
473
|
+
log(message[messageIndex])
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
if (HashMap.size(annotations) > 0) {
|
|
478
|
+
for (const [key, value] of annotations) {
|
|
479
|
+
log(color(`${key}:`, colors.bold, colors.white), value)
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
if (!processIsBun) console.groupEnd()
|
|
484
|
+
}
|
|
485
|
+
)
|
|
486
|
+
}
|