Files
godoxy/internal/logging
yusing bd1ff9731d refactor(accesslog): restructure access logging; enhance console output format
Major refactoring of the access logging infrastructure to improve code organization and add proper console/stdout logging support.

- Renamed `Writer` interface to `File` and consolidated with `SupportRotate`
- Renamed `Log(req, res)` to `LogRequest(req, res)` for clarity
- Added new `ConsoleLogger` with zerolog console writer for formatted stdout output
- Moved type definitions to new `types.go` file
- Changed buffer handling from `[]byte` returns to `*bytes.Buffer` parameters
- Renamed internal files for clarity (`access_logger.go` → `file_access_logger.go`)
- Fixed fileserver access logging timing: moved logging after handler execution with defer
- Correct response handling in Fileserver
- Remove deprecated field `buffer_size`
- Simplify and removed unnecessary code

All callers have been updated to use the new APIs.
2026-01-21 14:32:28 +00:00
..

Logging Package

Structured logging capabilities for GoDoxy, including application logging, HTTP access logging, and in-memory log streaming.

Overview

This package provides structured logging for GoDoxy with three distinct subsystems:

  • Application Logger: Zerolog-based console logger with level-aware formatting
  • Access Logger: HTTP request/response logging with configurable formats, filters, and destinations
  • In-Memory Logger: Circular buffer with WebSocket streaming for real-time log viewing

Primary Consumers

  • internal/api/ - HTTP request logging
  • internal/route/ - Route-level access logging
  • WebUI - Real-time log streaming via WebSocket

Non-goals

  • Log aggregation across multiple GoDoxy instances
  • Persistent storage of application logs (access logs only)
  • Structured logging output to external systems (Datadog, etc.)

Stability

Internal package with stable APIs. Exported interfaces (AccessLogger, MemLogger) are stable.

Packages

accesslog/

HTTP request/response logging with configurable formats, filters, and destinations.

See accesslog/README.md for full documentation.

memlogger/

In-memory circular buffer with WebSocket streaming for real-time log viewing.

See memlogger/README.md for full documentation.

Architecture

graph TB
    subgraph "Application Logger"
        L[logging.go] --> Z[zerolog.Logger]
        Z --> CW[ConsoleWriter]
    end

    subgraph "Access Log Pipeline"
        R[HTTP Request] --> M[Middleware]
        M --> RR[ResponseRecorder]
        RR --> F[Formatter]
        F --> B[BufferedWriter]
        B --> W[Writer]
        W --> F1[File]
        W --> S[Stdout]
    end

    subgraph "In-Memory Logger"
        WB[Write Buffer]
        WB --> RB[Circular Buffer<br/>16KB max]
        RB --> WS[WebSocket]
        WS --> C[Client]
    end

Configuration Surface

Access Log Configuration

See accesslog/README.md for configuration options.

In-Memory Logger

See memlogger/README.md for configuration options.

Dependency and Integration Map

Internal Dependencies

  • internal/task/task.go - Lifetime management
  • internal/maxmind/ - IP geolocation for ACL logging
  • pkg/gperr - Error handling

External Dependencies

  • github.com/rs/zerolog - Structured logging
  • github.com/puzpuzpuz/xsync/v4 - Concurrent maps
  • golang.org/x/time/rate - Error rate limiting

Observability

Logs

Level When
Debug Buffer size adjustments, rotation checks
Info Log rotation events, file opens/closes
Error Write failures (rate-limited)

Failure Modes and Recovery

Failure Mode Impact Recovery
File write failure Log entries dropped Rate-limited error logging; task termination after 5 errors
Disk full Rotation fails Continue logging until space available
WebSocket client disconnect Client misses logs Client reconnects to receive new logs
Buffer overflow (memlogger) Oldest entries truncated Automatic truncation at 50% threshold

Testing Notes

  • access_logger_test.go - Integration tests with mock file system
  • file_logger_test.go - Reference counting tests
  • back_scanner_test.go - Rotation boundary tests