Using a Custom Logger with `Effect.tryPromise` in Effect Typescript Library

Hello guys,is anyone know how to use custom logger with Effect.tryPromise ?I notice the documents just use Effect.gen

sample code is :

import { convertHTMLToMarkdownUnderMainContent, extractBodyHTML } from "@/lib/utils/htmlParser/extractHTML.ts";
import { Effect, Either, Logger, LogLevel } from "effect";
import { ofetch } from "ofetch";
import { getLoggerLayer } from "@/lib/combinators/logger/index.ts";

/**
 * Given the ID of a WeChat article, crawl the article content.
 * @param identifiedId 
 * @returns 
 */
export const crawlerWechatContent = (identifiedId: string) => Effect.tryPromise({
    try: async () => {
        const html = await ofetch<string>(`https://mp.wixin.qq.com/s/${identifiedId}`)
        const markdown = convertHTMLToMarkdownUnderMainContent(html)
        return {
            rawHTML: html,
            markdown: markdown
        }
    },
    catch: (error) => {
        Effect.runSync(Effect.logError(`Failed to crawl WeChat article with ID ${identifiedId}`, error)) // Supposed to use custom logger but it indeedly not
        Effect.runSync(Effect.logTrace(error))
        return new Error(`Failed to crawl WeChat article with ID ${identifiedId}`)
    }
})

Effect.runFork(crawlerWechatContent('123').pipe(
    Logger.withMinimumLogLevel(LogLevel.Error), 
    Effect.provide(getLoggerLayer('./logs/crawlerWechatContent.log'))
))
Was this page helpful?