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

Function prettyLoggerTty

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

Source from the content-addressed store, hash-verified

352}
353
354const prettyLoggerTty = (options: {
355 readonly colors: boolean
356 readonly stderr: boolean
357 readonly formatDate: (date: Date) => string
358}) => {
359 const color = options.colors ? withColor : withColorNoop
360 return makeLogger<unknown, void>(
361 ({ annotations, cause, context, date, fiberId, logLevel, message: message_, spans }) => {
362 const services = FiberRefs.getOrDefault(context, defaultServices.currentServices)
363 const console = Context.get(services, consoleTag).unsafe
364 const log = options.stderr === true ? console.error : console.log
365
366 const message = Arr.ensure(message_)
367
368 let firstLine = color(`[${options.formatDate(date)}]`, colors.white)
369 + ` ${color(logLevel.label, ...logLevelColors[logLevel._tag])}`
370 + ` (${fiberId_.threadName(fiberId)})`
371
372 if (List.isCons(spans)) {
373 const now = date.getTime()
374 const render = logSpan_.render(now)
375 for (const span of spans) {
376 firstLine += " " + render(span)
377 }
378 }
379
380 firstLine += ":"
381 let messageIndex = 0
382 if (message.length > 0) {
383 const firstMaybeString = structuredMessage(message[0])
384 if (typeof firstMaybeString === "string") {
385 firstLine += " " + color(firstMaybeString, colors.bold, colors.cyan)
386 messageIndex++
387 }
388 }
389
390 log(firstLine)
391 console.group()
392
393 if (!Cause.isEmpty(cause)) {
394 log(Cause.pretty(cause, { renderErrorCause: true }))
395 }
396
397 if (messageIndex < message.length) {
398 for (; messageIndex < message.length; messageIndex++) {
399 log(Inspectable.redact(message[messageIndex]))
400 }
401 }
402
403 if (HashMap.size(annotations) > 0) {
404 for (const [key, value] of annotations) {
405 log(color(`${key}:`, colors.bold, colors.white), Inspectable.redact(value))
406 }
407 }
408
409 console.groupEnd()
410 }
411 )

Callers 1

prettyLoggerFunction · 0.85

Calls 10

structuredMessageFunction · 0.85
groupEndMethod · 0.80
makeLoggerFunction · 0.70
renderFunction · 0.70
logFunction · 0.70
getMethod · 0.65
groupMethod · 0.65
isEmptyMethod · 0.65
sizeMethod · 0.65
colorFunction · 0.50

Tested by

no test coverage detected