MCPcopy Create free account
hub / github.com/Effect-TS/effect / prettyLoggerBrowser

Function prettyLoggerBrowser

packages/effect/src/internal/logger.ts:422–490  ·  view source on GitHub ↗
(options: {
  readonly colors: boolean
  readonly formatDate: (date: Date) => string
})

Source from the content-addressed store, hash-verified

420}
421
422const prettyLoggerBrowser = (options: {
423 readonly colors: boolean
424 readonly formatDate: (date: Date) => string
425}) => {
426 const color = options.colors ? "%c" : ""
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 message = Arr.ensure(message_)
432
433 let firstLine = `${color}[${options.formatDate(date)}]`
434 const firstParams = []
435 if (options.colors) {
436 firstParams.push("color:gray")
437 }
438 firstLine += ` ${color}${logLevel.label}${color} (${fiberId_.threadName(fiberId)})`
439 if (options.colors) {
440 firstParams.push(logLevelStyle[logLevel._tag], "")
441 }
442 if (List.isCons(spans)) {
443 const now = date.getTime()
444 const render = logSpan_.render(now)
445 for (const span of spans) {
446 firstLine += " " + render(span)
447 }
448 }
449
450 firstLine += ":"
451
452 let messageIndex = 0
453 if (message.length > 0) {
454 const firstMaybeString = structuredMessage(message[0])
455 if (typeof firstMaybeString === "string") {
456 firstLine += ` ${color}${firstMaybeString}`
457 if (options.colors) {
458 firstParams.push("color:deepskyblue")
459 }
460 messageIndex++
461 }
462 }
463
464 console.groupCollapsed(firstLine, ...firstParams)
465
466 if (!Cause.isEmpty(cause)) {
467 console.error(...Cause.prettyErrors(cause))
468 }
469
470 if (messageIndex < message.length) {
471 for (; messageIndex < message.length; messageIndex++) {
472 console.log(Inspectable.redact(message[messageIndex]))
473 }
474 }
475
476 if (HashMap.size(annotations) > 0) {
477 for (const [key, value] of annotations) {
478 const redacted = Inspectable.redact(value)
479 if (options.colors) {

Callers 1

prettyLoggerFunction · 0.85

Calls 10

structuredMessageFunction · 0.85
groupCollapsedMethod · 0.80
groupEndMethod · 0.80
makeLoggerFunction · 0.70
renderFunction · 0.70
getMethod · 0.65
isEmptyMethod · 0.65
errorMethod · 0.65
logMethod · 0.65
sizeMethod · 0.65

Tested by

no test coverage detected