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

Function lifecycleLog

packages/sql/pg/test/utils.ts:15–34  ·  view source on GitHub ↗
(id: string, step: string, state: string, ms: number, error?: unknown)

Source from the content-addressed store, hash-verified

13const lifecycleEnabled = process.env.PG_LIFECYCLE_DIAGNOSTICS === "1"
14const lifecycleFile = process.env.PG_LIFECYCLE_LOG
15const lifecycleLog = (id: string, step: string, state: string, ms: number, error?: unknown) => {
16 if (!lifecycleEnabled) return
17 const line = `[pg-lifecycle] ${new Date().toISOString()} pid=${process.pid} ${id} ${step} ${state} ${ms}ms${
18 error === undefined ? "" : ` error=${inspect(error)}`
19 }\n`
20 // Bypass the reporter, which can drop console output from hooks. Diagnostics
21 // must not turn successful cleanup into a failure or replace its original error.
22 try {
23 process.stderr.write(line)
24 } catch {}
25 if (lifecycleFile !== undefined) {
26 try {
27 Fs.appendFileSync(lifecycleFile, line)
28 } catch (error) {
29 try {
30 process.stderr.write(`[pg-lifecycle] unable to append diagnostics: ${inspect(error)}\n`)
31 } catch {}
32 }
33 }
34}
35
36const lifecycle = async <A>(id: string, step: string, run: () => Promise<A>, signal?: AbortSignal): Promise<A> => {
37 if (!lifecycleEnabled) return run()

Callers 4

logFunction · 0.85
lifecycleFunction · 0.85
markerFunction · 0.85
utils.tsFile · 0.85

Calls 2

writeMethod · 0.65
inspectFunction · 0.50

Tested by

no test coverage detected