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
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_cronto respect externally configuredlog_pathandlog_dirsettings.Currently, many
ncbo_croncomponents create log files without checking whether the target directory exists or is writable, which can result in:ontologies_apithat importncbo_cronAdditionally, the lack of stdout/stderr logging support makes it less than ideal to run
ncbo_cronin containerized environments which expect logs to go to stdoutProposal
Create a module
NcboCron::LoggerFactorythat:logger_for(component_name)methodlog_path-derived files likescheduler-ontologies-report.log[timestamp] [component] [level] messagestdout/stderrwhen desired (e.g., in Docker or tests)use_custom_logger(name, logger)Example output: