MCPcopy Index your code
hub / github.com/Effect-TS/effect / prettyLoggerBrowser

Function prettyLoggerBrowser

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

Source from the content-addressed store, hash-verified

412}
413
414const 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) {

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