Skip to content

Commit

Permalink
logging foundation
Browse files Browse the repository at this point in the history
  • Loading branch information
ktactac-ornl committed Mar 5, 2024
1 parent 7b62984 commit df55890
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 3 deletions.
31 changes: 31 additions & 0 deletions docs/source/logging.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Logging
=========

GARNET uses the Mantid logging framework.

Mantid provides 7 built-in logging levels:
- Debug
- Information
- Notice
- Warning
- Error
- Critical
- Fatal

Mantid convention reserves debug for developers and the rest available to the user.
The information level should be used by default.

Users can configure the logging framework in the GARNET configuration file.

More information is available in the `Mantid logging documentation <https://developer.mantidproject.org/Logging.html>`_.


Logging in Python
-------------------
Developers can access the logger with

.. code-block:: python
from mantid.kernel import logger
logger.information("This logs to the information level...")
logger.error("...and this to the error level.")
8 changes: 8 additions & 0 deletions logging.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
logging.loggers.root.level = information
logging.loggers.root.channel.class = SplitterChannel
logging.loggers.root.channel.channel1 = consoleChannel
logging.channels.consoleChannel.class = ConsoleChannel
logging.channels.consoleChannel.formatter = f1
logging.formatters.f1.class = PatternFormatter
logging.formatters.f1.pattern = %s-[%p] %t
logging.formatters.f1.times = local
13 changes: 10 additions & 3 deletions src/garnet/garnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys
from typing import Any

from mantid.kernel import Logger
from mantidqt.gui_helper import set_matplotlib_backend
from qtpy.QtWidgets import QApplication, QMainWindow

Expand All @@ -16,7 +15,14 @@
from garnet.mainwindow import MainWindow # noqa: E402
from garnet.version import __version__ # noqa: E402

logger = Logger("PACKAGENAME")
from mantid.kernel import logger
from garnet.logging.logging import init_logging


import os


init_logging()


class Garnet(QMainWindow):
Expand All @@ -37,8 +43,9 @@ def __new__(cls: Any) -> QMainWindow:
def __init__(self: Any, parent: QMainWindow = None) -> None:
"""Initialize the main window"""
super().__init__(parent)
logger.information(f"GARNET version: {__version__}")

logger.information(f"GARNET version: {__version__}")

self.setWindowTitle(f"GARNET - {__version__}")
self.main_window = MainWindow(self)
self.setCentralWidget(self.main_window)
Expand Down
41 changes: 41 additions & 0 deletions src/garnet/logging/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
GARNET logging framework for models
"""

from mantid.kernel import logger
from mantid.kernel import ConfigService


from configobj import ConfigObj



def init_logging():
"""
Pass logging configurations from the conf file
"""

conf_svc = ConfigService.Instance()

LOGGING_CONF = "logging.conf"
conf = ConfigObj(LOGGING_CONF)

for option in conf:
if 'logging' in option:
conf_svc.setString(option, conf[option])














0 comments on commit df55890

Please sign in to comment.