Переглянути джерело

refactor: cleanup debug and verbose logging across service and web

- Removed excessive console.log and debug statements from service modules
- Cleaned up HandBrake progress tracking logs while keeping essential error handling
- Removed config/database initialization debug output
- Simplified task queue and watcher event logging
- Removed file discovery and task creation verbose logs
- Kept error and warning logs for troubleshooting
- Fixed SVG title attribute type error in StatsSection
Timothy Pomeroy 1 місяць тому
батько
коміт
364c576061

+ 0 - 2
apps/service/src/app.controller.ts

@@ -177,8 +177,6 @@ export class AppController {
       }
     }
 
-    console.log(`Final processingPreset: ${processingPreset}`);
-
     // Determine destination and ext from dataset config
     let destination: string | undefined;
     let ext = '.mkv'; // Default extension

+ 0 - 4
apps/service/src/config.service.ts

@@ -30,10 +30,6 @@ export class ConfigService {
     this.dataDir = path.resolve(projectRoot, 'data');
     this.unifiedDbPath = path.resolve(this.dataDir, 'database.db');
 
-    console.log('ConfigService: Database path:', this.unifiedDbPath);
-    console.log('ConfigService: Project root:', projectRoot);
-    console.log('ConfigService: Current working directory:', process.cwd());
-
     // Ensure database and tables exist
     const db = new Database(this.unifiedDbPath);
     db.exec(`

+ 1 - 10
apps/service/src/db.service.ts

@@ -39,22 +39,16 @@ export class DbService {
     }
 
     const rootDataPath = path.resolve(projectRoot, 'data/database.db');
-    console.log('Database path:', rootDataPath);
-    console.log('Project root:', projectRoot);
-    console.log('Current working directory:', process.cwd());
 
     // Ensure the directory exists
     const dir = path.dirname(rootDataPath);
-    console.log('Database directory:', dir);
 
     if (!fs.existsSync(dir)) {
-      console.log('Creating database directory...');
       fs.mkdirSync(dir, { recursive: true });
     }
 
     try {
       this.db = new Database(rootDataPath);
-      console.log('Database opened successfully');
       this.migrate();
     } catch (error) {
       console.error('Failed to open database:', error);
@@ -128,9 +122,7 @@ export class DbService {
           rec.date || null,
         );
       }
-      // Optionally log: console.log(`Migrated ${json.files.length} records from ${dataset}.json`);
     }
-    // Optionally log: console.log('Migration complete.');
   }
 
   private migrate() {
@@ -187,9 +179,8 @@ export class DbService {
       if (!existingColumns.includes(col.name)) {
         try {
           this.db.exec(`ALTER TABLE tasks ADD COLUMN ${col.name} ${col.type}`);
-          console.log(`Added missing column: ${col.name}`);
         } catch (error) {
-          console.warn(`Could not add column ${col.name}:`, error.message);
+          // Column may already exist or migration not needed
         }
       }
     }

+ 0 - 25
apps/service/src/handbrake.service.ts

@@ -95,15 +95,11 @@ export class HandbrakeService {
       // Check for case-insensitive match
       const existingPath = this.findExistingDirCaseInsensitive(proposedPath);
       if (existingPath) {
-        this.logger.log(
-          `Found existing directory with different case: ${existingPath} (wanted: ${proposedPath})`,
-        );
         currentPath = existingPath;
       } else {
         // Directory doesn't exist, create it
         try {
           mkdirSync(proposedPath, { recursive: false });
-          this.logger.log(`Created directory: ${proposedPath}`);
           currentPath = proposedPath;
         } catch (err) {
           throw new Error(
@@ -130,7 +126,6 @@ export class HandbrakeService {
 
         try {
           actualOutputDir = this.ensureOutputDirectory(outputDir);
-          this.logger.log(`Output directory ready: ${actualOutputDir}`);
         } catch (err) {
           this.logger.error(
             `Failed to prepare output directory: ${outputDir}`,
@@ -160,8 +155,6 @@ export class HandbrakeService {
 
         hb.stdout.on('data', (data) => {
           const str = data.toString();
-          this.logger.debug(`HandBrake stdout: ${str}`);
-          console.log('[STDOUT]', str);
           // Parse progress from stdout - try multiple patterns
           let progressMatch = str.match(
             /Encoding: task \d+ of \d+, (\d+(?:\.\d+)?)\s*%/,
@@ -172,30 +165,16 @@ export class HandbrakeService {
           }
           if (progressMatch) {
             const percent = Math.round(parseFloat(progressMatch[1]));
-            console.log(
-              `[MATCH] Found progress: ${percent}%, lastPercent: ${lastPercent}, taskId: ${taskId}`,
-            );
             if (percent !== lastPercent) {
               lastPercent = percent;
               progressStarted = true;
 
-              console.log(`[UPDATE] Progress ${percent}% for task ${taskId}`);
-
               // Update task progress if we have a task ID
               if (taskId) {
-                console.log(
-                  `[DB] Updating task ${taskId} progress to ${percent}%`,
-                );
                 this.db.updateTask(taskId, { progress: percent });
-                console.log(`[DB] Update complete`);
-              } else {
-                console.warn('[WARN] No taskId provided!');
               }
 
               // Emit progress update
-              console.log(
-                `[WS] Emitting progress event for task ${taskId}: ${percent}%`,
-              );
               this.eventsGateway.emitTaskUpdate({
                 type: 'progress',
                 taskId,
@@ -205,16 +184,12 @@ export class HandbrakeService {
                 preset,
                 progress: percent,
               });
-              console.log(`[WS] Emit complete`);
             }
           }
-          this.logger.log(str);
         });
 
         hb.stderr.on('data', (data) => {
           const str = data.toString();
-          this.logger.debug(`HandBrake stderr: ${str}`);
-          console.log('[STDERR]', str);
           // Parse progress from stderr as fallback - try multiple patterns
           let progressMatch = str.match(
             /Encoding: task \d+ of \d+, (\d+(?:\.\d+)?)\s*%/,

+ 0 - 14
apps/service/src/task-queue.service.ts

@@ -60,7 +60,6 @@ export class TaskQueueService implements OnModuleInit {
       retryDelay: settings.retryDelay || 30000, // 30 seconds default
       processingInterval: settings.processingInterval || 5000, // 5 seconds default
     };
-    this.logger.log('Loaded queue settings:', this.queueSettings);
   }
 
   updateQueueSettings(settings: Partial<QueueSettings>) {
@@ -70,7 +69,6 @@ export class TaskQueueService implements OnModuleInit {
     this.config.setSettings({
       queue: { ...currentSettings, ...settings },
     });
-    this.logger.log('Updated queue settings:', this.queueSettings);
 
     // Restart processing with new interval if changed
     if (settings.processingInterval && this.processingInterval) {
@@ -85,16 +83,13 @@ export class TaskQueueService implements OnModuleInit {
 
   onModuleInit() {
     // Don't start processing automatically - wait for explicit start command
-    this.logger.log('Task queue initialized - processing stopped by default');
   }
 
   startProcessing() {
     if (this.processingInterval) {
-      this.logger.warn('Task queue processing already running');
       return;
     }
 
-    this.logger.log('Starting automatic task processing');
     this.processingInterval = setInterval(() => {
       this.processPendingTasks();
     }, this.queueSettings.processingInterval);
@@ -104,7 +99,6 @@ export class TaskQueueService implements OnModuleInit {
     if (this.processingInterval) {
       clearInterval(this.processingInterval);
       this.processingInterval = null;
-      this.logger.log('Stopped automatic task processing');
     }
   }
 
@@ -204,8 +198,6 @@ export class TaskQueueService implements OnModuleInit {
 
         // Check if enough time has passed for retry
         if (timeSinceFailure >= this.queueSettings.retryDelay) {
-          this.logger.log(`Retrying task ${task.id} (attempt ${retryCount})`);
-
           // Reset task for retry
           this.db.updateTask(task.id, {
             status: 'pending',
@@ -258,10 +250,6 @@ export class TaskQueueService implements OnModuleInit {
             preset: task.preset,
             success: true,
           });
-
-          this.logger.log(
-            `Task ${task.id} skipped - output file already exists: ${task.output}`,
-          );
           return;
         }
       }
@@ -296,8 +284,6 @@ export class TaskQueueService implements OnModuleInit {
           preset: task.preset,
           success: true,
         });
-
-        this.logger.log(`Task ${task.id} completed successfully`);
       } else {
         throw new Error('Handbrake processing failed');
       }

+ 0 - 29
apps/service/src/watcher.service.ts

@@ -54,15 +54,12 @@ export class WatcherService {
     this.lastOptions = conservativeOptions;
     this.watcher
       .on('add', (file: string) => {
-        this.logger.log(`File added: ${file}`);
         this.handleFileAdded(file);
       })
       .on('change', (file: string) => {
-        this.logger.log(`File changed: ${file}`);
         this.eventsGateway.emitFileUpdate({ type: 'change', file });
       })
       .on('unlink', (file: string) => {
-        this.logger.log(`File removed: ${file}`);
         this.eventsGateway.emitFileUpdate({ type: 'unlink', file });
       })
       .on('error', (error: Error) => {
@@ -72,7 +69,6 @@ export class WatcherService {
           error: error.message,
         });
       });
-    this.logger.log('Watcher started.');
     this.eventsGateway.emitWatcherUpdate({
       type: 'started',
       watches: enabledWatches,
@@ -90,7 +86,6 @@ export class WatcherService {
 
     // Check if this is a video file (basic extension check)
     if (!this.isVideoFile(file)) {
-      this.logger.log(`Skipping non-video file: ${file}`);
       return;
     }
 
@@ -105,9 +100,6 @@ export class WatcherService {
     const datasetSettings = datasetConfig[dataset];
 
     if (!datasetSettings || !datasetSettings.enabled) {
-      this.logger.log(
-        `Dataset ${dataset} is not enabled, skipping file: ${file}`,
-      );
       return;
     }
 
@@ -251,7 +243,6 @@ export class WatcherService {
       if (!fs.existsSync(outputDir)) {
         try {
           fs.mkdirSync(outputDir, { recursive: true });
-          this.logger.log(`Created output directory: ${outputDir}`);
         } catch (error) {
           this.logger.error(
             `Failed to create output directory ${outputDir}: ${error.message}`,
@@ -289,9 +280,6 @@ export class WatcherService {
     const outputExists = fs.existsSync(output);
 
     if (outputExists) {
-      this.logger.log(
-        `Output file already exists, skipping automatic task creation: ${output}`,
-      );
       return;
     }
 
@@ -300,19 +288,12 @@ export class WatcherService {
     if (existingTask) {
       // If task exists and is currently processing, reset to pending for retry
       if (existingTask.status === 'processing') {
-        this.logger.log(
-          `Resetting stuck processing task ${existingTask.id} to pending for file: ${file}`,
-        );
         this.taskQueue.updateTaskStatus(existingTask.id, 'pending');
         this.eventsGateway.emitTaskUpdate({
           type: 'reset',
           taskId: existingTask.id,
           file,
         });
-      } else {
-        this.logger.log(
-          `Task already exists for file: ${file} (status: ${existingTask.status})`,
-        );
       }
       return;
     }
@@ -327,14 +308,6 @@ export class WatcherService {
       });
 
       // Update file record to indicate processing has started
-      this.db.setFile(dataset, file, {
-        status: 'pending',
-        date: new Date().toISOString(),
-      });
-
-      this.logger.log(`Created task ${task.id} for file: ${file}`);
-
-      // Emit file update event
       this.eventsGateway.emitFileUpdate({
         type: 'add',
         file,
@@ -443,11 +416,9 @@ export class WatcherService {
     if (this.watcher && this.isWatching) {
       await this.watcher.close();
       this.isWatching = false;
-      this.logger.log('Watcher stopped.');
       this.eventsGateway.emitWatcherUpdate({ type: 'stopped' });
       return { stopped: true };
     }
-    this.logger.warn('Watcher is not running.');
     return { stopped: false, message: 'Watcher is not running.' };
   }
 

+ 1 - 1
apps/web/src/app/components/StatsSection.tsx

@@ -470,8 +470,8 @@ export default function StatsSection() {
                           viewBox="0 0 24 24"
                           strokeWidth="1.5"
                           stroke="currentColor"
-                          title={fileName}
                         >
+                          <title>{fileName}</title>
                           <path
                             strokeLinecap="round"
                             strokeLinejoin="round"