Logging

The RDMC Prototype uses Python’s built-in logging module with a custom setup to track process lifecycle, errors, and user actions. Logs are written to both the console and daily rotating log files.

To use logging in any module, import the logger and the log_process decorator:

import logging
from RDMC_Proto.log_utils import log_process

logger = logging.getLogger('app')

Logging a message directly:

logger.info("Something happened.")
logger.warning("Something looks wrong.")
logger.error("Something failed.")

Using the @log_process decorator:

The @log_process decorator is the recommended way to log any function or process. It automatically logs when a process starts, completes, or fails — including the user who triggered it if a request is available.

@log_process("Save Artifact details to DB")
def save_artifact(request, artifact_id):
    ...

This will produce log entries like:

2026-05-15 10:00:00 [INFO] app: Process 'Save Artifact details to DB' has started.
2026-05-15 10:00:01 [INFO] app: Process 'Save Artifact details to DB' completed successfully.

If the function raises an error:

2026-05-15 10:00:01 [ERROR] app: Process 'Save Artifact details to DB' failed with an error: <detail>

The logging configuration is defined in settings.py under the LOGGING key.

Format:

All log messages follow this format:

%(asctime)s [%(levelname)s] %(name)s: %(message)s

Example output:

2026-05-15 10:00:00 [INFO] app: Process 'Publish Container' has started.

Handlers:

Two handlers are active:

  • console — prints all DEBUG and above messages to the terminal.

  • daily_file — writes logs to a new file each day, stored in the Logs directory. Log files older than 30 days are automatically deleted.


Log files are created daily and stored under the Logs directory.

General log file (all app-level messages):

logs/
└── rdmc.2026-05-15.log

User-specific log file (when a request with an authenticated user is present):

logs/
└── alice_bob/
    └── rdmc.2026-05-15.log

The filename follows the pattern:

<prefix>.<YYYY-MM-DD>.log

Files older than 30 days are automatically cleaned up on each new log rotation.