import { appendFile } from "node:fs/promises"
import { join } from "node:path"

export const log = async (...messages: any[]) => {
  const timestamp = new Date().toISOString()
  // Append the messages to the app.txt file
  const logDir = process.env.DATA_DIR || join(import.meta.dirname, "../data")
  const logPath = join(logDir, "app.txt")
  await appendFile(logPath, `[${timestamp}] ${JSON.stringify(messages, null, 2)}\n`)
}
