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

Function format

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

Source from the content-addressed store, hash-verified

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