areibman / areibman/bottleneck

Feature: Integrate electron-log for comprehensive logging and debugging

Open
#17 0 comments 0 reactions 0 assignees View on GitHub
in-progress
Dominant language
TypeScript
Stars
156
Forks
21
PR merge metrics
No merged PRs in 30d

Description

## Feature Request

Integrate electron-log to provide robust logging capabilities for debugging issues in production and development environments.

## Description

electron-log is essential for debugging Electron apps as it provides file-based logging that persists across app sessions, making it possible to diagnose issues that occur on user machines where traditional console debugging isn't available.

## Why electron-log?

### Key Benefits
- Logs persist to files (crucial for debugging user issues)
- Works in both main and renderer processes
- Automatic log rotation and size management
- Multiple log levels (error, warn, info, verbose, debug, silly)
- Console.log override for seamless integration
- Remote log collection capability
- Structured logging with metadata
- Cross-platform log file locations

## Implementation Requirements

### Basic Setup
```javascript
// Main process
const log = require('electron-log');

// Configure log settings
log.transports.file.level = 'info';
log.transports.file.maxSize = 10 * 1024 * 1024; // 10MB
log.transports.file.format = '{h}:{i}:{s}.{ms} [{level}] {text}';
log.transports.file.inspectArguments = true;

// Override console.log in production
if (process.env.NODE_ENV === 'production') {
Object.assign(console, log.functions);
}

// Renderer process
const log = require('electron-log/renderer');
log.info('Renderer process started');
```

### Log File Locations
- **Windows**: `%USERPROFILE%\AppData\Roaming\{app name}\logs\`
- **macOS**: `~/Library/Logs/{app name}/`
- **Linux**: `~/.config/{app name}/logs/`

### Features to Implement

#### Log Categories
- Application lifecycle events
- API requests and responses
- Error stack traces
- Performance metrics
- User actions
- System information
- Update process
- Critical operations

#### Log Rotation
```javascript
log.transports.file.archiveLog = (file) => {
const date = new Date().toISOString().split('T')[0];
return file.replace('.log', `-${date}.log`);
};
log.transports.file.maxSize = 10485760; // 10MB
```

#### Structured Logging
```javascript
// Add metadata to all logs
log.variables.version = app.getVersion();
log.variables.userId = getUserId();
log.variables.sessionId = generateSessionId();

// Log with context
log.scope('auth').info('User logged in', {
userId: user.id,
timestamp: Date.now(),
method: 'OAuth'
});
```

#### Error Handling Integration
```javascript
// Catch unhandled errors
process.on('uncaughtException', (error) => {
log.error('Uncaught Exception:', error);
// Also send to Sentry if integrated
});

process.on('unhandledRejection', (error) => {
log.error('Unhandled Rejection:', error);
});

// Window errors
window.addEventListener('error', (event) => {
log.error('Window error:', event.error);
});
```

### Remote Logging
```javascript
// Send logs to remote server for analysis
log.transports.remote = {
level: 'error',
url: 'https://logs.example.com/api/logs',
headers: {
'Authorization': 'Bearer TOKEN'
},
format: (log) => ({
...log,
app: 'bottleneck',
version: app.getVersion(),
platform: process.platform
})
};
```

### Debug Features

#### Log Viewer in App
- Built-in log viewer window
- Filter by level, time, category
- Search functionality
- Export logs feature
- Clear logs option

#### Performance Logging
```javascript
class PerformanceLogger {
startTimer(label) {
log.time(label);
}

endTimer(label) {
log.timeEnd(label);
}

logMetrics() {
const metrics = {
memory: process.memoryUsage(),
uptime: process.uptime(),
cpuUsage: process.cpuUsage()
};
log.info('Performance metrics:', metrics);
}
}
```

### User Privacy
- Sanitize sensitive information
- User consent for log collection
- PII scrubbing rules
- GDPR compliance

### Development vs Production

#### Development
- Console output enabled
- Verbose logging level
- Pretty printing
- No remote logging

#### Production
- File output only
- Info level and above
- Compressed format
- Optional remote logging
- Automatic cleanup of old logs

### Integration with Support

#### Export Logs Feature
```javascript
async function exportLogs() {
const logPath = log.transports.file.getFile().path;
const zipPath = await createLogBundle(logPath);
await shareLogBundle(zipPath);
}
```

#### Diagnostic Report
- System information
- App configuration
- Recent errors
- Performance metrics
- Last 1000 log entries

## Benefits

- **Debugging**: Diagnose issues on user machines
- **Support**: Users can share logs for troubleshooting
- **Monitoring**: Track app health and usage patterns
- **Development**: Better debugging during development
- **Performance**: Identify performance bottlenecks
- **Compliance**: Audit trail for critical operations

## Acceptance Criteria

- [ ] electron-log integrated in main and renderer processes
- [ ] Logs written to appropriate platform directories
- [ ] Log rotation working (10MB max file size)
- [ ] Different log levels properly configured
- [ ] Sensitive data sanitization implemented
- [ ] Console.log redirected in production
- [ ] Unhandled errors captured in logs
- [ ] Log viewer UI implemented (optional)
- [ ] Export logs functionality available
- [ ] Remote logging configured (optional)
- [ ] Performance logging implemented
- [ ] Documentation for log analysis
- [ ] Log cleanup for old files
- [ ] No performance impact from logging

## Configuration Example

```json
{
"logging": {
"level": "info",
"maxFileSize": "10MB",
"maxFiles": 5,
"format": "json",
"categories": ["app", "api", "auth", "performance"],
"remote": {
"enabled": false,
"endpoint": "https://logs.example.com",
"level": "error"
},
"privacy": {
"scrubPatterns": ["password", "token", "key"],
"anonymizeIPs": true
}
}
}
```

## Resources

- [electron-log Documentation](https://github.com/megahertz/electron-log)
- [Logging Best Practices](https://www.npmjs.com/package/electron-log#readme)
- [Electron Debugging Guide](https://www.electronjs.org/docs/latest/tutorial/debugging-main-process)

🤖 Generated with [Claude Code](https://claude.ai/code)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the linked electron-log documentation and Electron debugging guide, then inspect the app's main and renderer process entry points. The issue is done only when the required logging, rotation, sanitization, error capture, performance, cleanup, export, and documentation criteria are defined and implemented; optional viewer and remote logging scope still needs clarification.

Written by the indexing model from the issue text.

Assessment

Tech stack
electron, typescript
Domain
desktop, observability-sre
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.