Skip to content

Commit e88d244

Browse files
fix logging
1 parent 755026c commit e88d244

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

stagehand/src/index.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -214,43 +214,43 @@ const consoleLogs: string[] = [];
214214
const operationLogs: string[] = [];
215215

216216
function log(message: string, level: 'info' | 'error' | 'debug' = 'info') {
217-
// const timestamp = new Date().toISOString();
218-
// const logMessage = `[${timestamp}] [${level.toUpperCase()}] ${message}`;
219-
// operationLogs.push(logMessage);
217+
const timestamp = new Date().toISOString();
218+
const logMessage = `[${timestamp}] [${level.toUpperCase()}] ${message}`;
219+
operationLogs.push(logMessage);
220220

221-
// // Write to file
222-
// fs.appendFileSync(LOG_FILE, logMessage + '\n');
221+
// Write to file
222+
fs.appendFileSync(LOG_FILE, logMessage + '\n');
223223

224-
// // Console output to stderr
225-
// if (process.env.DEBUG || level === 'error') {
226-
// console.error(logMessage);
227-
// }
224+
// Console output to stderr
225+
if (process.env.DEBUG || level === 'error') {
226+
console.error(logMessage);
227+
}
228228

229-
// // Send logging message to client for important events
230-
// if (serverInstance && (level === 'info' || level === 'error')) {
231-
// serverInstance.sendLoggingMessage({
232-
// level: level,
233-
// data: message,
234-
// });
235-
// }
229+
// Send logging message to client for important events
230+
if (serverInstance && (level === 'info' || level === 'error')) {
231+
serverInstance.sendLoggingMessage({
232+
level: level,
233+
data: message,
234+
});
235+
}
236236
}
237237

238238
function logRequest(type: string, params: any) {
239-
// const requestLog = {
240-
// timestamp: new Date().toISOString(),
241-
// type,
242-
// params,
243-
// };
244-
// log(`REQUEST: ${JSON.stringify(requestLog, null, 2)}`, 'debug');
239+
const requestLog = {
240+
timestamp: new Date().toISOString(),
241+
type,
242+
params,
243+
};
244+
log(`REQUEST: ${JSON.stringify(requestLog, null, 2)}`, 'debug');
245245
}
246246

247247
function logResponse(type: string, response: any) {
248-
// const responseLog = {
249-
// timestamp: new Date().toISOString(),
250-
// type,
251-
// response,
252-
// };
253-
// log(`RESPONSE: ${JSON.stringify(responseLog, null, 2)}`, 'debug');
248+
const responseLog = {
249+
timestamp: new Date().toISOString(),
250+
type,
251+
response,
252+
};
253+
log(`RESPONSE: ${JSON.stringify(responseLog, null, 2)}`, 'debug');
254254
}
255255

256256
// Ensure Stagehand is initialized
@@ -506,6 +506,7 @@ const server = new Server(
506506
capabilities: {
507507
resources: {},
508508
tools: {},
509+
logging: {},
509510
},
510511
}
511512
);

0 commit comments

Comments
 (0)