Skip to content

Conversation

jmborr
Copy link
Member

@jmborr jmborr commented Sep 29, 2025

Description of work

This PR enhances the log_to_python() function in the Python logging utility to accept an optional pattern argument for formatting log messages. The change allows users to specify custom formatting patterns when forwarding Mantid log messages to Python's logging framework.

Key Changes
Added optional pattern parameter to log_to_python() function with default value None
Updated function to only apply pattern configuration when a pattern is provided
Removed the hard-coded "%t" pattern and made it configurable

This does not require release notes. The change is limited to internal API functionality, with no impact on user-facing features, GUI interfaces, or workflows.

EWM 11991
PR against ornl-next: #40020

To test:

In an environment such as mantid-developer, run script:

import logging

from mantid.simpleapi import *
from mantid.utils.logging import log_to_python 

log_to_python(level="information", pattern="Hello [%s] %t")  # creates python standard logger with the name of "Mantid"
logging.getLogger("Mantid").setLevel(logging.INFO)

# create a file handler
fileHandler = logging.FileHandler("/tmp/test_40019.log")
fileHandler.setLevel(logging.INFO)
fileHandler.setFormatter(logging.Formatter("%(message)s"))
logging.getLogger("Mantid").addHandler(fileHandler)

# Ouptut INFO messages created by algorithm CreateEmptyTableWorkspace
ws = CreateEmptyTableWorkspace()

Then verify the contents of "/tmp/test_40019.log":

Hello [CreateEmptyTableWorkspace] CreateEmptyTableWorkspace started
....

Reviewer

Your comments will be used as part of the gatekeeper process. Comment clearly on what you have checked and tested during your review. Provide an audit trail for any changes requested.

As per the review guidelines:

  • Is the code of an acceptable quality? (Code standards/GUI standards)
  • Has a thorough functional test been performed? Do the changes handle unexpected input/situations?
  • Are appropriately scoped unit and/or system tests provided?
  • Do the release notes conform to the guidelines and describe the changes appropriately?
  • Has the relevant (user and developer) documentation been added/updated?

Gatekeeper

As per the gatekeeping guidelines:

  • Has a thorough first line review been conducted, including functional testing?
  • At a high-level, is the code quality sufficient?
  • Are the base, milestone and labels correct?

…y and functionality

Signed-off-by: Jose Borreguero <borreguero@gmail.com>
@jmborr jmborr added this to the Release 6.15 milestone Sep 29, 2025
@jmborr jmborr requested a review from Copilot September 29, 2025 17:56
@jmborr jmborr self-assigned this Sep 29, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the log_to_python() function in the Python logging utility to accept an optional pattern argument for formatting log messages. The change allows users to specify custom formatting patterns when forwarding Mantid log messages to Python's logging framework.

Key Changes

  • Added optional pattern parameter to log_to_python() function with default value None
  • Updated function to only apply pattern configuration when a pattern is provided
  • Removed the hard-coded "%t" pattern and made it configurable

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Framework/PythonInterface/mantid/utils/logging.py Added optional pattern parameter to log_to_python() function
docs/source/release/v6.14.0/Framework/LiveData/New_features/39186.rst Removed unrelated release note entry
Framework/LiveData/src/SNSLiveEventDataListener.cpp Code cleanup and comment improvements (unrelated to pattern feature)
Framework/LiveData/src/ADARA/ADARAParser.cpp Code cleanup and reorganization (unrelated to pattern feature)
Framework/LiveData/inc/MantidLiveData/SNSLiveEventDataListener.h Code cleanup and comment improvements (unrelated to pattern feature)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Signed-off-by: Jose Borreguero <borreguero@gmail.com>
Signed-off-by: Jose Borreguero <borreguero@gmail.com>
Signed-off-by: Jose Borreguero <borreguero@gmail.com>
Copy link
Member

@peterfpeterson peterfpeterson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main changes are to not override logging configuration by default.

The ADARA changes are renaming some variables and very unrelated. It would have been better as a separate PR, but I understand bundling it in.

Please add a reason why release notes aren't needed.

@KedoKudo KedoKudo merged commit d45da1d into main Oct 1, 2025
12 checks passed
@jmborr jmborr deleted the sns_live_listener branch October 1, 2025 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants