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

Function prettyLoggerTty

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

Source from the content-addressed store, hash-verified

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

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