(options: {
readonly colors: boolean
readonly formatDate: (date: Date) => string
})
| 412 | } |
| 413 | |
| 414 | const prettyLoggerBrowser = (options: { |
| 415 | readonly colors: boolean |
| 416 | readonly formatDate: (date: Date) => string |
| 417 | }) => { |
| 418 | const color = options.colors ? "%c" : "" |
| 419 | return makeLogger<unknown, void>( |
| 420 | ({ annotations, cause, context, date, fiberId, logLevel, message: message_, spans }) => { |
| 421 | const services = FiberRefs.getOrDefault(context, defaultServices.currentServices) |
| 422 | const console = Context.get(services, consoleTag).unsafe |
| 423 | const message = Arr.ensure(message_) |
| 424 | |
| 425 | let firstLine = `${color}[${options.formatDate(date)}]` |
| 426 | const firstParams = [] |
| 427 | if (options.colors) { |
| 428 | firstParams.push("color:gray") |
| 429 | } |
| 430 | firstLine += ` ${color}${logLevel.label}${color} (${fiberId_.threadName(fiberId)})` |
| 431 | if (options.colors) { |
| 432 | firstParams.push(logLevelStyle[logLevel._tag], "") |
| 433 | } |
| 434 | if (List.isCons(spans)) { |
| 435 | const now = date.getTime() |
| 436 | const render = logSpan_.render(now) |
| 437 | for (const span of spans) { |
| 438 | firstLine += " " + render(span) |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | firstLine += ":" |
| 443 | |
| 444 | let messageIndex = 0 |
| 445 | if (message.length > 0) { |
| 446 | const firstMaybeString = structuredMessage(message[0]) |
| 447 | if (typeof firstMaybeString === "string") { |
| 448 | firstLine += ` ${color}${firstMaybeString}` |
| 449 | if (options.colors) { |
| 450 | firstParams.push("color:deepskyblue") |
| 451 | } |
| 452 | messageIndex++ |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | console.groupCollapsed(firstLine, ...firstParams) |
| 457 | |
| 458 | if (!Cause.isEmpty(cause)) { |
| 459 | console.error(...Cause.prettyErrors(cause)) |
| 460 | } |
| 461 | |
| 462 | if (messageIndex < message.length) { |
| 463 | for (; messageIndex < message.length; messageIndex++) { |
| 464 | console.log(Inspectable.redact(message[messageIndex])) |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | if (HashMap.size(annotations) > 0) { |
| 469 | for (const [key, value] of annotations) { |
| 470 | const redacted = Inspectable.redact(value) |
| 471 | if (options.colors) { |
no test coverage detected