Skip to content

Conversation

jmborr
Copy link
Member

@jmborr jmborr commented Sep 29, 2025

Description of work

See #40019

…y and functionality

Signed-off-by: Jose Borreguero <borreguero@gmail.com>
@jmborr jmborr self-assigned this Sep 29, 2025
@jmborr jmborr added the ornl-next A copy of a branch into the ornl-next fork label Sep 29, 2025
Signed-off-by: Jose Borreguero <borreguero@gmail.com>
Signed-off-by: Jose Borreguero <borreguero@gmail.com>
Signed-off-by: Jose Borreguero <borreguero@gmail.com>
KedoKudo pushed a commit that referenced this pull request Oct 1, 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.

<!-- Please provide an outline and reasoning for the work.
If there is no linked issue provide context.
-->

EWM
[11991](https://ornlrse.clm.ibmcloud.com/ccm/web/projects/Neutron%20Data%20Project%20%28Change%20Management%29#action=com.ibm.team.workitem.viewWorkItem&id=11991)
PR against `ornl-next`: #40020 

<!-- If issue raised by user. Do not leak email addresses.
**Report to:** [user name]
-->

### To test:
In an environment such as `mantid-developer`, run script:
```python
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"`:
```bash
Hello [CreateEmptyTableWorkspace] CreateEmptyTableWorkspace started
....
```
<!-- Include sufficient instructions for someone unfamiliar with the
application to test.
Ok to refer back to instructions in the issue.
-->

<!-- REMEMBER:
- Add labels, milestones, etc.
- Ensure the base of this PR is correct (e.g. release-next or main)
- Add release notes in separate file as per
([guidelines](https://developer.mantidproject.org/Standards/ReleaseNotesGuide.html)),
or justify their absence:
*This does not require release notes* because <fill in an explanation of
why>
-->

<!--  GATEKEEPER: When squashing, remove the section from HERE...  -->
---

### 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](http://developer.mantidproject.org/ReviewingAPullRequest.html):

- Is the code of an acceptable quality? ([Code
standards](http://developer.mantidproject.org/Standards/)/[GUI
standards](http://developer.mantidproject.org/Standards/GUIStandards.html))
- 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](https://developer.mantidproject.org/Standards/ReleaseNotesGuide.html)
and describe the changes appropriately?
- Has the relevant (user and developer) documentation been
added/updated?

### Gatekeeper

As per the [gatekeeping
guidelines](https://developer.mantidproject.org/Gatekeeping.html):

- 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?
<!--  GATEKEEPER: ...To HERE  -->

---------

Signed-off-by: Jose Borreguero <borreguero@gmail.com>
@jmborr jmborr merged commit 3a2fb49 into ornl-next 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
ornl-next A copy of a branch into the ornl-next fork
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant