@@ -2,7 +2,7 @@ const stream = require('stream');
22const stripAnsi = require ( 'strip-ansi' ) ;
33const os = require ( 'os' ) ;
44const pid = process . pid ;
5-
5+ const isBun = typeof Bun !== 'undefined' ;
66const LogLevel = {
77 INFO : 'info' ,
88 ERROR : 'error'
@@ -108,7 +108,56 @@ const logCollector = {
108108 return ;
109109 }
110110
111- logStream . write = ( chunk , encoding , done ) => {
111+ if ( isBun ) {
112+ const stdoutMethods = [
113+ 'log' , 'info' , 'debug' , 'dir' , 'table' ,
114+ 'count' , 'countReset' , 'time' , 'timeLog' , 'timeEnd' ,
115+ 'group' , 'groupEnd'
116+ ] ;
117+ const stderrMethods = [ 'error' , 'warn' , 'trace' ] ;
118+
119+ stdoutMethods . forEach ( method => {
120+ console [ method ] = ( ...args ) => {
121+ const message = args . map ( arg =>
122+ typeof arg === 'object' ? JSON . stringify ( arg ) : arg
123+ ) . join ( ' ' ) ;
124+ const logEntry = {
125+ timestamp : new Date ( ) . toISOString ( ) ,
126+ message,
127+ source : 'console' ,
128+ level : LogLevel [ method . toUpperCase ( ) ] || LogLevel . INFO ,
129+ hostname : this . hostname ,
130+ pid : this . pid
131+ } ;
132+ this . logStream . write ( logEntry ) ;
133+ Bun . write ( Bun . stdout , `${ args } \n` ) ;
134+ } ;
135+ } ) ;
136+
137+ stderrMethods . forEach ( method => {
138+ console [ method ] = ( ...args ) => {
139+ const message = args . map ( arg =>
140+ typeof arg === 'object' ? JSON . stringify ( arg ) : arg
141+ ) . join ( ' ' ) ;
142+ const logEntry = {
143+ timestamp : new Date ( ) . toISOString ( ) ,
144+ message,
145+ source : 'console' ,
146+ level : LogLevel . ERROR ,
147+ hostname : this . hostname ,
148+ pid : this . pid
149+ } ;
150+
151+ this . logStream . write ( logEntry ) ;
152+ Bun . write ( Bun . stderr , `${ args } \n` ) ;
153+ } ;
154+ } ) ;
155+
156+ return ;
157+ }
158+
159+
160+ logStream . write = ( chunk , encoding , done ) => {
112161 const cleanedChunk = stripAnsi ( chunk . toString ( ) ) ;
113162 const logEntry = {
114163 timestamp : new Date ( ) . toISOString ( ) ,
0 commit comments