# reidmorrison/rails_semantic_logger architecture

> Architecture diagram of the GitHub repository reidmorrison/rails_semantic_logger, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/reidmorrison/rails_semantic_logger
- Repository: https://github.com/reidmorrison/rails_semantic_logger

## Overview

This project is a Ruby gem—specifically, Rails Semantic Logger—which’s purpose is to “patch” the standard Rails logger so that it uses Semantic Logger to provide structured, JSON-friendly logging instead of the standard plain-text logs. In other words, it integrates with Rails logging and extends it for better production monitoring, debugging, and centralized logging (with support for additional frameworks like Sidekiq).

##### Main Components
- Core Logger Module – Represented in the lib directory (e.g., lib/rails_semantic_logger.rb, lib/rails_semantic_logger/options.rb, and the gemspec). This is the central piece that ties everything together.
- Rails Integrations – The project patches and extends multiple Rails components:
– ActionController (e.g., log_subscriber and extensions in lib/rails_semantic_logger/action_controller and lib/rails_semantic_logger/extensions/action_controller).
– ActionMailer, ActiveJob, ActiveRecord, and ActionView similarly have their dedicated integration files.
– Extra middleware or integrations like for ActionCable, Sidekiq (under lib/rails_semantic_logger/sidekiq and its extensions), and others such as for ActiveSupport.
- Extension Modules – There are additional patches targeting external libraries and frameworks like Mongoid, Rack, and custom integrations for Rails components.
- Test/Dummy Application – Found under test/dummy. This represents a sample Rails application used to verify the integration, demonstrating how the gem “plugs in” to an actual Rails app.
- Community and CI Infrastructure – Reflected in directories such as .github (including workflows and issue templates) which support integration and contribution processes.

##### Architectural Relationships and Data Flow
- The central component is the Rails Semantic Logger core which intercepts logging calls from the Rails framework.
- Each integration module transforms a typical log call into a structured, JSON-formatted log entry using Semantic Logger.
- There’s a configuration layer (illustrated in the README’s sample configuration code) where the Rails application (or dummy app during tests) sets application-level logging behavior (such as JSON output, file or console appenders, etc.).

##### Design Patterns and Principles
- Extension/Decorator Pattern – The gem “decorates” the default Rails loggers with its own functionality without completely replacing every Rails component.
- Loose Coupling – Configuration files (gemfiles, CI workflows, etc.) indicate that the gem is designed to be flexible and automatically adjust behaviors depending on the environment (development, production, Kubernetes deployments).

## Diagram (Mermaid)

```mermaid
graph TD
    Dummy["Demo/Dummy Rails Application"]:::testApp

    subgraph "Gem Integration Modules"
        ACInt["ActionController Integration"]:::rails
        AMInt["ActionMailer Integration"]:::rails
        AVInt["ActionView Integration"]:::rails
        AJInt["ActiveJob Integration"]:::rails
        ARInt["ActiveRecord Integration"]:::rails
        DJInt["DelayedJob Integration"]:::rails
        SKInt["Sidekiq Integration"]:::rails
        ACableInt["ActionCable Integration"]:::rails
        ASInt["ActiveSupport & Other Extensions"]:::rails
    end

    Core["Rails Semantic Logger Core"]:::core
    External["Centralized Logging System"]:::external
    CI["Community & CI Infrastructure"]:::ci

    %% Logging flow from Dummy App to Integration Modules
    Dummy -->|"logs"| ACInt
    Dummy -->|"logs"| AMInt
    Dummy -->|"logs"| AVInt
    Dummy -->|"logs"| AJInt
    Dummy -->|"logs"| ARInt
    Dummy -->|"logs"| DJInt
    Dummy -->|"logs"| SKInt
    Dummy -->|"logs"| ACableInt
    Dummy -->|"logs"| ASInt

    %% Integration Modules forward processed logs to Core
    ACInt -->|"formats_JSON"| Core
    AMInt -->|"formats_JSON"| Core
    AVInt -->|"formats_JSON"| Core
    AJInt -->|"formats_JSON"| Core
    ARInt -->|"formats_JSON"| Core
    DJInt -->|"formats_JSON"| Core
    SKInt -->|"formats_JSON"| Core
    ACableInt -->|"formats_JSON"| Core
    ASInt -->|"formats_JSON"| Core

    %% Core sends structured logs to external system
    Core -->|"sends_structured_logs"| External

    %% CI infrastructure supports integration testing
    CI -->|"supports"| Dummy

    %% Click Events for Rails Semantic Logger Core
    click Core "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger.rb"
    click Core "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/options.rb"
    click Core "https://github.com/reidmorrison/rails_semantic_logger/blob/master/rails_semantic_logger.gemspec"

    %% Click Events for ActionController Integration
    click ACInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/action_controller/log_subscriber.rb"
    click ACInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/extensions/action_controller/live.rb"

    %% Click Event for ActionMailer Integration
    click AMInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/action_mailer/log_subscriber.rb"

    %% Click Events for ActionView Integration
    click AVInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/action_view/log_subscriber.rb"
    click AVInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/extensions/action_view/streaming_template_renderer.rb"

    %% Click Events for ActiveJob Integration
    click AJInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/active_job/log_subscriber.rb"
    click AJInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/extensions/active_job/logging.rb"

    %% Click Event for ActiveRecord Integration
    click ARInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/active_record/log_subscriber.rb"

    %% Click Event for DelayedJob Integration
    click DJInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/delayed_job/plugin.rb"

    %% Click Events for Sidekiq Integration
    click SKInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/sidekiq/defaults.rb"
    click SKInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/extensions/sidekiq/sidekiq.rb"

    %% Click Event for ActionCable Integration
    click ACableInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/extensions/action_cable/tagged_logger_proxy.rb"

    %% Click Events for ActiveSupport and Other Extensions
    click ASInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/extensions/active_support/log_subscriber.rb"
    click ASInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/extensions/active_support/logger.rb"
    click ASInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/extensions/active_support/tagged_logging.rb"
    click ASInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/extensions/mongoid/config.rb"
    click ASInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/extensions/rack/server.rb"
    click ASInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/extensions/rackup/server.rb"
    click ASInt "https://github.com/reidmorrison/rails_semantic_logger/blob/master/lib/rails_semantic_logger/extensions/rails/server.rb"

    %% Click Event for Test/Dummy Application
    click Dummy "https://github.com/reidmorrison/rails_semantic_logger/tree/master/test/dummy"

    %% Click Event for Community and CI Infrastructure
    click CI "https://github.com/reidmorrison/rails_semantic_logger/blob/master/.github"

    %% Styles
    classDef core fill:#f4cccc,stroke:#b45f06,stroke-width:2px;
    classDef rails fill:#cfe2f3,stroke:#3c78d8,stroke-width:2px;
    classDef testApp fill:#d9ead3,stroke:#6aa84f,stroke-width:2px;
    classDef external fill:#fff2cc,stroke:#bf9000,stroke-width:2px;
    classDef ci fill:#ead1dc,stroke:#b97a57,stroke-width:2px;
```
