Skip to content

Feature Request: Centralized Logger Factory with Component-Aware Formatting #90

Description

@alexskr

Feature Request: Centralized Logger Factory with Component-Aware Formatting

Summary

Introduce a centralized logger mechanism (NcboCron::LoggerFactory) to standardize how loggers are created across components, with per-component log file support and consistent log line formatting. Also support clean logging to stdout/stderr, which is ideal for containerized environments (e.g., Docker).

Motivation

This proposal continues the work from the #89 that refactored ncbo_cron to respect externally configured log_path and log_dir settings.

Currently, many ncbo_cron components create log files without checking whether the target directory exists or is writable, which can result in:

  • File permission errors (e.g., when trying to write to a nonexistent or protected path)
  • Inconsistent fallback behavior
  • Log files being created unintentionally in bundled gem directories or other shared environments
  • Problems with integration in components like ontologies_api that import ncbo_cron

Additionally, the lack of stdout/stderr logging support makes it less than ideal to run ncbo_cron in containerized environments which expect logs to go to stdout

Proposal

Create a module NcboCron::LoggerFactory that:

  • Provides a logger_for(component_name) method
  • Writes logs to log_path-derived files like scheduler-ontologies-report.log
  • Adds a consistent log formatter: [timestamp] [component] [level] message
  • Supports logging to stdout/stderr when desired (e.g., in Docker or tests)
  • Allows injecting test or shared loggers via use_custom_logger(name, logger)

Example output:

[2024-04-16 09:23:12] [ontologies-report] [INFO] Generating ontology report
[2024-04-16 09:23:14] [index-synchronizer] [DEBUG] Synchronization started

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions