@@ -34,3 +34,40 @@ export const consoleLogger: SkLogger = {
3434 warn : ( message : string , ...args : unknown [ ] ) => console . warn ( message , ...args ) , // eslint-disable-line no-console
3535 error : ( message : string , ...args : unknown [ ] ) => console . error ( message , ...args ) , // eslint-disable-line no-console
3636} ;
37+
38+ /**
39+ * File-based logger for Node.js debugging contexts
40+ * Appends logs to a file with timestamps
41+ */
42+ export function createFileLogger ( filePath : string ) : SkLogger {
43+ // Lazy import fs to avoid bundling issues
44+ let fs : any = null ;
45+
46+ const writeLog = ( level : string , message : string , ...args : unknown [ ] ) => {
47+ if ( ! fs ) {
48+ try {
49+ fs = require ( 'fs' ) ;
50+ } catch ( e ) {
51+ // File logging not available in this context
52+ return ;
53+ }
54+ }
55+
56+ const timestamp = new Date ( ) . toISOString ( ) ;
57+ const argsStr = args . length > 0 ? ' ' + JSON . stringify ( args ) : '' ;
58+ const logLine = `[${ timestamp } ] [${ level } ] ${ message } ${ argsStr } \n` ;
59+
60+ try {
61+ fs . appendFileSync ( filePath , logLine , 'utf8' ) ;
62+ } catch ( e ) {
63+ // Silently fail if we can't write to the file
64+ }
65+ } ;
66+
67+ return {
68+ debug : ( message : string , ...args : unknown [ ] ) => writeLog ( 'DEBUG' , message , ...args ) ,
69+ info : ( message : string , ...args : unknown [ ] ) => writeLog ( 'INFO' , message , ...args ) ,
70+ warn : ( message : string , ...args : unknown [ ] ) => writeLog ( 'WARN' , message , ...args ) ,
71+ error : ( message : string , ...args : unknown [ ] ) => writeLog ( 'ERROR' , message , ...args ) ,
72+ } ;
73+ }
0 commit comments