| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as FileSystem from "effect/FileSystem"; |
| 3 | import * as Logger from "effect/Logger"; |
| 4 | import { Path } from "effect/Path"; |
| 5 | import { AlchemyContext } from "../AlchemyContext.ts"; |
| 6 | |
| 7 | export const fileLogger = Effect.fn(function* ( |
| 8 | ...segments: ReadonlyArray<string> |
| 9 | ) { |
| 10 | const { dotAlchemy } = yield* AlchemyContext; |
| 11 | const fs = yield* FileSystem.FileSystem; |
| 12 | const path = yield* Path; |
| 13 | const logFile = path.join(dotAlchemy, "log", ...segments); |
| 14 | |
| 15 | yield* fs.makeDirectory(path.dirname(logFile), { recursive: true }); |
| 16 | |
| 17 | return yield* Logger.formatLogFmt.pipe( |
| 18 | Logger.toFile(logFile, { |
| 19 | flag: "a", |
| 20 | }), |
| 21 | ); |
| 22 | }); |