Home · Developers · Guides · Logging

Operations

Logging

Logging service and ring buffer

Nova Coder uses a structured logging system. Every action is logged with a timestamp, level, logger name, source file, and line number. JSON logging is supported for production environments.

Log Format

Text Format

2026-07-09 12:01:00 [INFO] novacoder.kernel - Planner task created (kernel.py:42)

JSON Format

{
  "timestamp": "2026-07-09T12:01:00+00:00",
  "level": "INFO",
  "logger": "novacoder.kernel",
  "message": "Planner task created",
  "source": "kernel.py",
  "line": 42
}

Configuration

logging:
  level: INFO
  format: text
  file_path: ~/.config/novacoder/novacoder.log
  console: true

Set format: json for machine-readable output.

Using the Logger

from novacoder.logging import get_logger

logger = get_logger("novacoder.workspace")
logger.info("Scanning project")
logger.error("Failed to read file", extra={"path": "main.py"})

The extra context is included in JSON log entries.

LoggingService

LoggingService is a kernel service that configures the root logger from the application configuration during boot. It attaches a BufferHandler that writes formatted records into novacoder.logging.buffer._log_buffer so the API and TUI can share a single log stream.

from novacoder.logging.service import LoggingService
from novacoder.config.settings import AppConfig

service = LoggingService(config=AppConfig())
service.initialize()
service.start()

Correlation IDs

Use ContextAdapter to attach correlation IDs to log entries:

logger = get_logger("novacoder.agents", extra={"correlation_id": "abc-123"})

Development Instructions

Adding a New Logger

  1. Use get_logger("novacoder.<module>") to create a logger in your module.
  2. Include extra metadata for events that need structured querying.
  3. Do not print directly to stdout.

Adding a Custom Formatter

  1. Subclass StructuredFormatter in novacoder/logging/logger.py.
  2. Add a new format name to LoggingConfig.
  3. Update configure_logging() to select the formatter based on config.

Testing Logging

Use caplog or attach a temporary handler in tests. The shared buffer can be inspected in tests via novacoder.logging.buffer.get_log_buffer().

def test_logs_info(caplog):
    with caplog.at_level("INFO"):
        logger.info("Started")
    assert "Started" in caplog.text

Best Practices

  • Always use get_logger instead of print.
  • Include structured extra metadata for important events.
  • Use log levels appropriately: DEBUG for detail, INFO for milestones, WARNING for recoverable issues, ERROR for failures.
  • Rotate log files in production deployments.

Source: wiki/logging.md · rendered 2026-11-10