mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-30 15:04:16 -07:00
refactor(logging): Centralize console logging with debugLogger (#11590)
This commit is contained in:
@@ -8,6 +8,7 @@ import type { Config } from '../config/config.js';
|
||||
import { isPerformanceMonitoringActive } from './metrics.js';
|
||||
import { getMemoryMonitor } from './memory-monitor.js';
|
||||
import { ActivityType } from './activity-types.js';
|
||||
import { debugLogger } from '../utils/debugLogger.js';
|
||||
|
||||
/**
|
||||
* Activity event data structure
|
||||
@@ -152,7 +153,7 @@ export class ActivityMonitor {
|
||||
listener(event);
|
||||
} catch (error) {
|
||||
// Silently catch listener errors to avoid disrupting the application
|
||||
console.debug('ActivityMonitor listener error:', error);
|
||||
debugLogger.debug('ActivityMonitor listener error:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ import {
|
||||
detectIdeFromEnv,
|
||||
isCloudShell,
|
||||
} from '../../ide/detect-ide.js';
|
||||
import { debugLogger } from '../../utils/debugLogger.js';
|
||||
|
||||
export enum EventNames {
|
||||
START_SESSION = 'start_session',
|
||||
@@ -238,7 +239,7 @@ export class ClearcutLogger {
|
||||
]);
|
||||
|
||||
if (wasAtCapacity && this.config?.getDebugMode()) {
|
||||
console.debug(
|
||||
debugLogger.debug(
|
||||
`ClearcutLogger: Dropped old event to prevent memory leak (queue size: ${this.events.size})`,
|
||||
);
|
||||
}
|
||||
@@ -282,14 +283,14 @@ export class ClearcutLogger {
|
||||
}
|
||||
|
||||
this.flushToClearcut().catch((error) => {
|
||||
console.debug('Error flushing to Clearcut:', error);
|
||||
debugLogger.debug('Error flushing to Clearcut:', error);
|
||||
});
|
||||
}
|
||||
|
||||
async flushToClearcut(): Promise<LogResponse> {
|
||||
if (this.flushing) {
|
||||
if (this.config?.getDebugMode()) {
|
||||
console.debug(
|
||||
debugLogger.debug(
|
||||
'ClearcutLogger: Flush already in progress, marking pending flush.',
|
||||
);
|
||||
}
|
||||
@@ -299,7 +300,7 @@ export class ClearcutLogger {
|
||||
this.flushing = true;
|
||||
|
||||
if (this.config?.getDebugMode()) {
|
||||
console.log('Flushing log events to Clearcut.');
|
||||
debugLogger.log('Flushing log events to Clearcut.');
|
||||
}
|
||||
const eventsToSend = this.events.toArray() as LogEventEntry[][];
|
||||
this.events.clear();
|
||||
@@ -359,7 +360,7 @@ export class ClearcutLogger {
|
||||
// Fire and forget the pending flush
|
||||
this.flushToClearcut().catch((error) => {
|
||||
if (this.config?.getDebugMode()) {
|
||||
console.debug('Error in pending flush to Clearcut:', error);
|
||||
debugLogger.debug('Error in pending flush to Clearcut:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -451,7 +452,7 @@ export class ClearcutLogger {
|
||||
// Flush start event immediately
|
||||
this.enqueueLogEvent(this.createLogEvent(EventNames.START_SESSION, data));
|
||||
this.flushToClearcut().catch((error) => {
|
||||
console.debug('Error flushing to Clearcut:', error);
|
||||
debugLogger.debug('Error flushing to Clearcut:', error);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -668,14 +669,14 @@ export class ClearcutLogger {
|
||||
logFlashFallbackEvent(): void {
|
||||
this.enqueueLogEvent(this.createLogEvent(EventNames.FLASH_FALLBACK, []));
|
||||
this.flushToClearcut().catch((error) => {
|
||||
console.debug('Error flushing to Clearcut:', error);
|
||||
debugLogger.debug('Error flushing to Clearcut:', error);
|
||||
});
|
||||
}
|
||||
|
||||
logRipgrepFallbackEvent(): void {
|
||||
this.enqueueLogEvent(this.createLogEvent(EventNames.RIPGREP_FALLBACK, []));
|
||||
this.flushToClearcut().catch((error) => {
|
||||
console.debug('Error flushing to Clearcut:', error);
|
||||
debugLogger.debug('Error flushing to Clearcut:', error);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -811,7 +812,7 @@ export class ClearcutLogger {
|
||||
// Flush immediately on session end.
|
||||
this.enqueueLogEvent(this.createLogEvent(EventNames.END_SESSION, []));
|
||||
this.flushToClearcut().catch((error) => {
|
||||
console.debug('Error flushing to Clearcut:', error);
|
||||
debugLogger.debug('Error flushing to Clearcut:', error);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -910,7 +911,7 @@ export class ClearcutLogger {
|
||||
this.createLogEvent(EventNames.EXTENSION_INSTALL, data),
|
||||
);
|
||||
this.flushToClearcut().catch((error) => {
|
||||
console.debug('Error flushing to Clearcut:', error);
|
||||
debugLogger.debug('Error flushing to Clearcut:', error);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -930,7 +931,7 @@ export class ClearcutLogger {
|
||||
this.createLogEvent(EventNames.EXTENSION_UNINSTALL, data),
|
||||
);
|
||||
this.flushToClearcut().catch((error) => {
|
||||
console.debug('Error flushing to Clearcut:', error);
|
||||
debugLogger.debug('Error flushing to Clearcut:', error);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -962,7 +963,7 @@ export class ClearcutLogger {
|
||||
this.createLogEvent(EventNames.EXTENSION_UPDATE, data),
|
||||
);
|
||||
this.flushToClearcut().catch((error) => {
|
||||
console.debug('Error flushing to Clearcut:', error);
|
||||
debugLogger.debug('Error flushing to Clearcut:', error);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1047,7 +1048,7 @@ export class ClearcutLogger {
|
||||
this.createLogEvent(EventNames.EXTENSION_ENABLE, data),
|
||||
);
|
||||
this.flushToClearcut().catch((error) => {
|
||||
console.debug('Error flushing to Clearcut:', error);
|
||||
debugLogger.debug('Error flushing to Clearcut:', error);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1082,7 +1083,7 @@ export class ClearcutLogger {
|
||||
this.createLogEvent(EventNames.EXTENSION_DISABLE, data),
|
||||
);
|
||||
this.flushToClearcut().catch((error) => {
|
||||
console.debug('Error flushing to Clearcut:', error);
|
||||
debugLogger.debug('Error flushing to Clearcut:', error);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1240,7 +1241,7 @@ export class ClearcutLogger {
|
||||
|
||||
getConfigJson() {
|
||||
const configJson = safeJsonStringifyBooleanValuesOnly(this.config);
|
||||
console.debug(configJson);
|
||||
debugLogger.debug(configJson);
|
||||
return safeJsonStringifyBooleanValuesOnly(this.config);
|
||||
}
|
||||
|
||||
@@ -1254,7 +1255,7 @@ export class ClearcutLogger {
|
||||
|
||||
// Log a warning if we're dropping events
|
||||
if (eventsToSend.length > MAX_RETRY_EVENTS && this.config?.getDebugMode()) {
|
||||
console.warn(
|
||||
debugLogger.warn(
|
||||
`ClearcutLogger: Dropping ${
|
||||
eventsToSend.length - MAX_RETRY_EVENTS
|
||||
} events due to retry queue limit. Total events: ${
|
||||
@@ -1269,7 +1270,7 @@ export class ClearcutLogger {
|
||||
|
||||
if (numEventsToRequeue === 0) {
|
||||
if (this.config?.getDebugMode()) {
|
||||
console.debug(
|
||||
debugLogger.debug(
|
||||
`ClearcutLogger: No events re-queued (queue size: ${this.events.size})`,
|
||||
);
|
||||
}
|
||||
@@ -1292,7 +1293,7 @@ export class ClearcutLogger {
|
||||
}
|
||||
|
||||
if (this.config?.getDebugMode()) {
|
||||
console.debug(
|
||||
debugLogger.debug(
|
||||
`ClearcutLogger: Re-queued ${numEventsToRequeue} events for retry (queue size: ${this.events.size})`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import {
|
||||
GcpLogExporter,
|
||||
} from './gcp-exporters.js';
|
||||
import { TelemetryTarget } from './index.js';
|
||||
import { debugLogger } from '../utils/debugLogger.js';
|
||||
|
||||
// For troubleshooting, set the log level to DiagLogLevel.DEBUG
|
||||
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
|
||||
@@ -184,7 +185,7 @@ export function initializeTelemetry(config: Config): void {
|
||||
try {
|
||||
sdk.start();
|
||||
if (config.getDebugMode()) {
|
||||
console.log('OpenTelemetry SDK started successfully.');
|
||||
debugLogger.log('OpenTelemetry SDK started successfully.');
|
||||
}
|
||||
telemetryInitialized = true;
|
||||
initializeMetrics(config);
|
||||
@@ -211,7 +212,7 @@ export async function shutdownTelemetry(config: Config): Promise<void> {
|
||||
ClearcutLogger.getInstance()?.shutdown();
|
||||
await sdk.shutdown();
|
||||
if (config.getDebugMode()) {
|
||||
console.log('OpenTelemetry SDK shut down successfully.');
|
||||
debugLogger.log('OpenTelemetry SDK shut down successfully.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error shutting down SDK:', error);
|
||||
|
||||
Reference in New Issue
Block a user