File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,7 +21,8 @@ const args = {
2121 logs : {
2222 type : "boolean" ,
2323 default : false ,
24- description : "Write logs to the app directory" ,
24+ description :
25+ "Write logs to the app directory. Only works with emulate-streaming" ,
2526 } ,
2627} satisfies ArgsDef
2728
Original file line number Diff line number Diff line change 1- import fs from "node:fs"
1+ import fs from "node:fs/promises "
22
33import { CONFIG } from "~/config/config"
44import { PATHS } from "~/config/paths"
55
66export function initializeLogger ( ) {
77 if ( ! CONFIG . LOGGING_ENABLED ) return
88
9- fs . mkdirSync ( PATHS . LOG_PATH , { recursive : true } )
9+ return fs . mkdir ( PATHS . LOG_PATH , { recursive : true } )
1010}
1111
12- export function logToFile ( type : string , message : string ) {
12+ export async function logToFile ( type : string , message : string ) {
1313 if ( ! CONFIG . LOGGING_ENABLED ) return
1414
1515 const timestamp = new Date ( ) . toISOString ( )
16- fs . appendFileSync ( PATHS . LOG_FILE , `${ timestamp } ${ type } : ${ message } \n` )
16+ await fs . appendFile ( PATHS . LOG_FILE , `${ timestamp } ${ type } : ${ message } \n` )
1717}
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { streamSSE } from "hono/streaming"
55
66import type { ChatCompletionsPayload } from "~/services/copilot/chat-completions/types"
77
8+ import { logToFile } from "~/lib/logger"
89import { chatCompletions } from "~/services/copilot/chat-completions/service"
910
1011import { createContentChunk , createFinalChunk , segmentResponse } from "./utils"
@@ -22,8 +23,10 @@ export async function handler(c: Context) {
2223 } ) )
2324
2425 consola . info ( "Received request:" , loggedPayload )
26+ await logToFile ( "REQUEST" , JSON . stringify ( payload , null , 2 ) )
2527
2628 const response = await chatCompletions ( payload )
29+ await logToFile ( "RESPONSE" , JSON . stringify ( response , null , 2 ) )
2730
2831 if ( payload . stream ) {
2932 consola . info ( `Response from Copilot: ${ JSON . stringify ( response ) } ` )
You can’t perform that action at this time.
0 commit comments