|
10 | 10 | from eyelet.application.services import ConfigurationService, HookService |
11 | 11 | from eyelet.domain.models import Handler, HandlerType, Hook, HookType, ToolMatcher |
12 | 12 | from eyelet.infrastructure.repositories import InMemoryHookRepository |
| 13 | +from eyelet.services.config_service import ConfigService |
| 14 | +from eyelet.domain.config import LogFormat, LogScope |
13 | 15 |
|
14 | 16 | console = Console() |
15 | 17 |
|
@@ -399,3 +401,124 @@ def install_all(ctx, scope, force, dev): |
399 | 401 | import traceback |
400 | 402 | console.print(f"[red]Error installing hooks: {e}[/red]") |
401 | 403 | console.print(f"[dim]{traceback.format_exc()}[/dim]") |
| 404 | + |
| 405 | + |
| 406 | +@configure.command() |
| 407 | +@click.option('--format', |
| 408 | + help='Logging format(s) - comma-separated list (e.g., "json", "sqlite", "json,sqlite")') |
| 409 | +@click.option('--scope', type=click.Choice(['global', 'project', 'both']), |
| 410 | + help='Logging scope (global ~/.claude, project local, or both)') |
| 411 | +@click.option('--enabled/--disabled', default=None, |
| 412 | + help='Enable or disable logging') |
| 413 | +@click.option('--global', 'is_global', is_flag=True, |
| 414 | + help='Configure global settings instead of project') |
| 415 | +@click.pass_context |
| 416 | +def logging(ctx, format, scope, enabled, is_global): |
| 417 | + """ |
| 418 | + Configure logging settings - Chart the course! |
| 419 | + |
| 420 | + Configure how Eyelet logs hook executions. You can choose: |
| 421 | + - Format: JSON files, SQLite database, or multiple formats |
| 422 | + - Scope: Global (~/.claude), project-local, or both |
| 423 | + - Enable/disable logging entirely |
| 424 | + |
| 425 | + Examples: |
| 426 | + # Enable SQLite logging for current project |
| 427 | + eyelet configure logging --format sqlite |
| 428 | + |
| 429 | + # Use both JSON and SQLite globally |
| 430 | + eyelet configure logging --format json,sqlite --scope global --global |
| 431 | + |
| 432 | + # Disable logging temporarily |
| 433 | + eyelet configure logging --disabled |
| 434 | + |
| 435 | + # Show current settings |
| 436 | + eyelet configure logging |
| 437 | + """ |
| 438 | + config_service = ConfigService() |
| 439 | + |
| 440 | + # If no options provided, show current settings |
| 441 | + if format is None and scope is None and enabled is None: |
| 442 | + config = config_service.get_config() |
| 443 | + console.print("\n[bold]Current Logging Configuration[/bold]") |
| 444 | + console.print(f"Format: [cyan]{config.logging.format.value}[/cyan]") |
| 445 | + console.print(f"Scope: [cyan]{config.logging.scope.value}[/cyan]") |
| 446 | + console.print(f"Enabled: [cyan]{'Yes' if config.logging.enabled else 'No'}[/cyan]") |
| 447 | + |
| 448 | + if is_global: |
| 449 | + console.print("\n[dim]Showing global configuration[/dim]") |
| 450 | + else: |
| 451 | + # Check if there's a project override |
| 452 | + project_config = config_service.load_project_config() |
| 453 | + if project_config and project_config.logging: |
| 454 | + console.print("\n[dim]Project configuration overrides global settings[/dim]") |
| 455 | + else: |
| 456 | + console.print("\n[dim]Using global configuration (no project override)[/dim]") |
| 457 | + return |
| 458 | + |
| 459 | + # Load appropriate config |
| 460 | + if is_global: |
| 461 | + config = config_service.load_global_config() |
| 462 | + else: |
| 463 | + config = config_service.load_project_config() or config_service.get_config() |
| 464 | + |
| 465 | + # Update settings |
| 466 | + changed = False |
| 467 | + |
| 468 | + if format is not None: |
| 469 | + # Parse comma-separated formats |
| 470 | + formats = [f.strip().lower() for f in format.split(',')] |
| 471 | + |
| 472 | + # Validate formats |
| 473 | + valid_formats = ['json', 'sqlite'] |
| 474 | + for fmt in formats: |
| 475 | + if fmt not in valid_formats: |
| 476 | + console.print(f"[red]Invalid format: {fmt}[/red]") |
| 477 | + console.print(f"Valid formats: {', '.join(valid_formats)}") |
| 478 | + return |
| 479 | + |
| 480 | + # Determine the LogFormat enum value |
| 481 | + if len(formats) == 1: |
| 482 | + config.logging.format = LogFormat(formats[0]) |
| 483 | + elif set(formats) == {'json', 'sqlite'}: |
| 484 | + config.logging.format = LogFormat.BOTH |
| 485 | + else: |
| 486 | + # For future expansion when we have more formats |
| 487 | + console.print("[yellow]Warning: Multiple format support currently limited to json,sqlite[/yellow]") |
| 488 | + config.logging.format = LogFormat.BOTH |
| 489 | + |
| 490 | + changed = True |
| 491 | + |
| 492 | + if scope is not None: |
| 493 | + config.logging.scope = LogScope(scope) |
| 494 | + changed = True |
| 495 | + |
| 496 | + if enabled is not None: |
| 497 | + config.logging.enabled = enabled |
| 498 | + changed = True |
| 499 | + |
| 500 | + if changed: |
| 501 | + # Save the configuration |
| 502 | + if is_global: |
| 503 | + config_service.save_global_config(config) |
| 504 | + else: |
| 505 | + config_service.save_project_config(config) |
| 506 | + |
| 507 | + console.print(f"\n[green]✓ Logging configuration updated![/green]") |
| 508 | + console.print(f"Format: [cyan]{config.logging.format.value}[/cyan]") |
| 509 | + console.print(f"Scope: [cyan]{config.logging.scope.value}[/cyan]") |
| 510 | + console.print(f"Enabled: [cyan]{'Yes' if config.logging.enabled else 'No'}[/cyan]") |
| 511 | + |
| 512 | + # Show where config was saved |
| 513 | + saved_path = config_service.global_config_path if is_global else config_service.project_config_path |
| 514 | + console.print(f"\n[dim]Configuration saved to: {saved_path}[/dim]") |
| 515 | + |
| 516 | + # Special message for SQLite |
| 517 | + if config.logging.format in [LogFormat.SQLITE, LogFormat.BOTH]: |
| 518 | + console.print("\n[bold cyan]SQLite logging enabled![/bold cyan]") |
| 519 | + console.print("Hook executions will be stored in SQLite databases:") |
| 520 | + if config.logging.scope in [LogScope.GLOBAL, LogScope.BOTH]: |
| 521 | + console.print(" • Global: ~/.claude/eyelet-logs/hooks.db") |
| 522 | + if config.logging.scope in [LogScope.PROJECT, LogScope.BOTH]: |
| 523 | + console.print(" • Project: .eyelet-logs/hooks.db") |
| 524 | + console.print("\n[dim]Use 'eyelet query' commands to explore the data[/dim]") |
0 commit comments