Skip to content

Commit f5f489d

Browse files
authored
Merge pull request #153 from errsole/feat/bun-compatibility
Feat/bun compatibility
2 parents 3b9d3d7 + 54000a9 commit f5f489d

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

lib/main/logs/index.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const stream = require('stream');
22
const stripAnsi = require('strip-ansi');
33
const os = require('os');
44
const pid = process.pid;
5-
5+
const isBun = typeof Bun !== 'undefined';
66
const 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

Comments
 (0)