refactor(core): replace legacy logger with Effect logging (#31310)

This commit is contained in:
Dax
2026-06-08 15:41:56 -04:00
committed by GitHub
parent af9dff96df
commit a5ddb7f291
152 changed files with 698 additions and 2243 deletions
+8 -18
View File
@@ -8,11 +8,8 @@ import { mergeDeep } from "remeda"
import { Config } from "@/config/config"
import { RuntimeFlags } from "@/effect/runtime-flags"
import { errorMessage } from "@/util/error"
import * as Log from "@opencode-ai/core/util/log"
import * as Formatter from "./formatter"
const log = Log.create({ service: "format" })
export const Status = Schema.Struct({
name: Schema.String,
extensions: Schema.Array(Schema.String),
@@ -60,11 +57,7 @@ export const layer = Layer.effect(
const matching = Object.values(formatters).filter((item) => item.extensions.includes(ext))
const checks = await Promise.all(
matching.map(async (item) => {
log.info("checking", { name: item.name, ext })
const cmd = await getCommand(item)
if (cmd) {
log.info("enabled", { name: item.name, ext })
}
return {
item,
cmd,
@@ -78,13 +71,13 @@ export const layer = Layer.effect(
function formatFile(filepath: string) {
return Effect.gen(function* () {
log.info("formatting", { file: filepath })
yield* Effect.logInfo("formatting", { file: filepath })
const formatters = yield* Effect.promise(() => getFormatter(path.extname(filepath)))
if (!formatters.length) return false
for (const { item, cmd } of formatters) {
log.info("running", { command: cmd })
yield* Effect.logInfo("running", { command: cmd })
const replaced = cmd.map((x) => x.replace("$FILE", filepath))
const dir = yield* InstanceState.directory
const result = yield* appProcess
@@ -100,20 +93,17 @@ export const layer = Layer.effect(
)
.pipe(
Effect.catch((error) =>
Effect.sync(() => {
log.error("failed to format file", {
Effect.logError("failed to format file", {
error: "spawn failed",
command: cmd,
...item.environment,
file: filepath,
cause: errorMessage(error.cause ?? error),
})
return undefined
}),
}).pipe(Effect.as(undefined)),
),
)
if (result && result.exitCode !== 0) {
log.error("failed", {
yield* Effect.logError("failed", {
command: cmd,
...item.environment,
})
@@ -127,8 +117,8 @@ export const layer = Layer.effect(
const cfg = yield* config.get()
if (!cfg.formatter) {
log.info("all formatters are disabled")
log.info("init")
yield* Effect.logInfo("all formatters are disabled")
yield* Effect.logInfo("init")
return {
formatters,
isEnabled,
@@ -166,7 +156,7 @@ export const layer = Layer.effect(
}
}
log.info("init")
yield* Effect.logInfo("init")
return {
formatters,