mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-21 02:24:09 -07:00
Allow telemetry exporters to GCP to utilize user's login credentials, if requested (#13778)
This commit is contained in:
committed by
GitHub
parent
92e95ed806
commit
b9b3b8050d
@@ -4,6 +4,9 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import * as fs from 'node:fs';
|
||||
import * as util from 'node:util';
|
||||
|
||||
/**
|
||||
* A simple, centralized logger for developer-facing debug messages.
|
||||
*
|
||||
@@ -17,19 +20,47 @@
|
||||
* will intercept these calls and route them to the debug drawer UI.
|
||||
*/
|
||||
class DebugLogger {
|
||||
private logStream: fs.WriteStream | undefined;
|
||||
|
||||
constructor() {
|
||||
this.logStream = process.env['GEMINI_DEBUG_LOG_FILE']
|
||||
? fs.createWriteStream(process.env['GEMINI_DEBUG_LOG_FILE'], {
|
||||
flags: 'a',
|
||||
})
|
||||
: undefined;
|
||||
// Handle potential errors with the stream
|
||||
this.logStream?.on('error', (err) => {
|
||||
// Log to console as a fallback, but don't crash the app
|
||||
console.error('Error writing to debug log stream:', err);
|
||||
});
|
||||
}
|
||||
|
||||
private writeToFile(level: string, args: unknown[]) {
|
||||
if (this.logStream) {
|
||||
const message = util.format(...args);
|
||||
const timestamp = new Date().toISOString();
|
||||
const logEntry = `[${timestamp}] [${level}] ${message}\n`;
|
||||
this.logStream.write(logEntry);
|
||||
}
|
||||
}
|
||||
|
||||
log(...args: unknown[]): void {
|
||||
this.writeToFile('LOG', args);
|
||||
console.log(...args);
|
||||
}
|
||||
|
||||
warn(...args: unknown[]): void {
|
||||
this.writeToFile('WARN', args);
|
||||
console.warn(...args);
|
||||
}
|
||||
|
||||
error(...args: unknown[]): void {
|
||||
this.writeToFile('ERROR', args);
|
||||
console.error(...args);
|
||||
}
|
||||
|
||||
debug(...args: unknown[]): void {
|
||||
this.writeToFile('DEBUG', args);
|
||||
console.debug(...args);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user