# zhongjunjimmy/log-msg architecture

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

- Interactive diagram: https://gitdiagram.com/zhongjunjimmy/log-msg
- Repository: https://github.com/zhongjunjimmy/log-msg

## Overview

##### Project type and purpose
- This is an open-source Node.js utility library (“log-msg”) published on NPM.
- Its purpose is to provide a configurable logging API for other Node.js applications, allowing console output and optional file-based logging with different log levels (DEBUG, INFO, WARN, ERROR).

##### File structure
- Top level
- index.js – the module entry point that exports the logMsg factory
- lib/logMsg.js – core implementation of the logger
- examples/demo.js – shows how a consumer would call the API
- test/test.js – unit tests verifying behavior
- .github/workflows/test.yml – CI pipeline to run tests on push
- package.json / package-lock.json – defines dependencies, scripts, and metadata
- README.md / LICENSE – documentation and license
- Patterns
- Single-module library
- Factory pattern: index.js returns an instance configured by the user
- Separation of concerns: log formatting, console output, file I/O

##### README for additional insights
- Describes configuration options (writeLog, logPath, prefixName, and per-level flags)
- Explains two main methods: log() (handles level-based formatting and console output) and writeLogFile() (handles file writes)

##### Elements
- Clear labels (e.g., “Consumer App,” “logMsg Factory,” “Logger Instance,” “Console,” “File System”)
- Factory invocation → Logger instance creation
- logger.log() calls → Console output
- logger.log() calls → writeLogFile() → File System

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Consumer Side"
        Consumer["Consumer App"]:::runtime
    end

    Consumer -->|"require('logMsg')(config)"| Factory["logMsg Factory (index.js)"]:::runtime
    Factory -->|"returns Logger instance"| Logger["Logger Instance"]:::runtime
    Factory -->|"accepts config"| Config["Configuration Object"]:::config

    subgraph "Runtime Processing"
        Logger -->|"log(type, msg)"| Formatter["Format & Level Check"]:::runtime
        Formatter -->|"formatted output"| Console["Console (stdout/stderr)"]:::runtime
        Formatter -->|"if writeLog=true"| FileWriter["writeLogFile()"]:::runtime
        FileWriter -->|"fs.appendFile"| FS["File System"]:::storage
        FS --> LogFile["Log File (persistent)"]:::storage
    end

    subgraph "Development"
        Tests["Unit Tests"]:::pipeline
        CI["CI Pipeline"]:::pipeline
        Package["package.json"]:::pipeline
        Doc["README.md"]:::pipeline
        License["LICENSE"]:::pipeline
        Tests -->|"runs on push"| CI
    end

    %% Click Events
    click Consumer "https://github.com/zhongjunjimmy/log-msg/blob/main/examples/demo.js"
    click Factory "https://github.com/zhongjunjimmy/log-msg/blob/main/index.js"
    click Logger "https://github.com/zhongjunjimmy/log-msg/blob/main/lib/logMsg.js"
    click Config "https://github.com/zhongjunjimmy/log-msg/blob/main/index.js"
    click Console "https://github.com/zhongjunjimmy/log-msg/blob/main/lib/logMsg.js"
    click FileWriter "https://github.com/zhongjunjimmy/log-msg/blob/main/lib/logMsg.js"
    click FS "https://github.com/zhongjunjimmy/log-msg/blob/main/lib/logMsg.js"
    click Tests "https://github.com/zhongjunjimmy/log-msg/blob/main/test/test.js"
    click CI "https://github.com/zhongjunjimmy/log-msg/blob/main/.github/workflows/test.yml"
    click Package "https://github.com/zhongjunjimmy/log-msg/blob/main/package.json"
    click Doc "https://github.com/zhongjunjimmy/log-msg/blob/main/README.md"
    click License "https://github.com/zhongjunjimmy/log-msg/tree/main/LICENSE"

    %% Styles
    classDef runtime fill:#D6EAF8,stroke:#1B4F72,color:#1B2631;
    classDef config fill:#D5F5E3,stroke:#196F3D,color:#1D8348;
    classDef storage fill:#FCF3CF,stroke:#B7950B,color:#7D6608;
    classDef pipeline fill:#F2F3F4,stroke:#566573,color:#1C2833;
```
