1import * as Effect from "effect/Effect";
2import * as FileSystem from "effect/FileSystem";
3import * as Logger from "effect/Logger";
4import { Path } from "effect/Path";
5import { AlchemyContext } from "../AlchemyContext.ts";
6
7export 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});