MCPcopy
hub / github.com/Effect-TS/effect / format

Function format

packages/effect/src/internal/logger.ts:179–209  ·  view source on GitHub ↗
(quoteValue: (s: string) => string, whitespace?: number | string | undefined)

Source from the content-addressed store, hash-verified

177 * @internal
178 */
179const format = (quoteValue: (s: string) => string, whitespace?: number | string | undefined) =>
180(
181 { annotations, cause, date, fiberId, logLevel, message, spans }: Logger.Logger.Options<unknown>
182): string => {
183 const formatValue = (value: string): string => value.match(textOnly) ? value : quoteValue(value)
184 const format = (label: string, value: string): string => `${logSpan_.formatLabel(label)}=${formatValue(value)}`
185 const append = (label: string, value: string): string => " " + format(label, value)
186
187 let out = format("timestamp", date.toISOString())
188 out += append("level", logLevel.label)
189 out += append("fiber", fiberId_.threadName(fiberId))
190
191 const messages = Arr.ensure(message)
192 for (let i = 0; i < messages.length; i++) {
193 out += append("message", Inspectable.toStringUnknown(messages[i], whitespace))
194 }
195
196 if (!Cause.isEmptyType(cause)) {
197 out += append("cause", Cause.pretty(cause, { renderErrorCause: true }))
198 }
199
200 for (const span of spans) {
201 out += " " + logSpan_.render(date.getTime())(span)
202 }
203
204 for (const [label, value] of annotations) {
205 out += append(label, Inspectable.toStringUnknown(value, whitespace))
206 }
207
208 return out
209}
210
211/** @internal */
212const escapeDoubleQuotes = (s: string) => `"${s.replace(/\\([\s\S])|(")/g, "\\$1$2")}"`

Callers 15

toStringFunction · 0.70
toStringFunction · 0.70
toStringFunction · 0.70
toStringMethod · 0.70
toStringMethod · 0.70
toStringMethod · 0.70
toStringFunction · 0.70
toStringFunction · 0.70
appendFunction · 0.70
logger.tsFile · 0.70
toStringMethod · 0.70
toStringMethod · 0.70

Calls 2

formatValueFunction · 0.85
appendFunction · 0.85

Tested by

no test coverage detected