diff --git a/docs/conf.py b/docs/conf.py index e26cc2c3..f29e6369 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,9 +25,9 @@ author = "Jason D. McEwen, Christopher G. R. Wallis, Matthew A. Price, Matthew M. Docherty, Alicja Polanska" # The short X.Y version -version = "1.2.2" +version = "1.2.3" # The full version, including alpha/beta/rc tags -release = "1.2.2" +release = "1.2.3" # -- General configuration --------------------------------------------------- diff --git a/logs/logging.yaml b/harmonic/default-logging-config.yaml similarity index 89% rename from logs/logging.yaml rename to harmonic/default-logging-config.yaml index 0ddc30e1..c71b0227 100644 --- a/logs/logging.yaml +++ b/harmonic/default-logging-config.yaml @@ -1,5 +1,5 @@ # ================================================== -# Logging setup for Harmonic Software package (2018) +# Logging setup for Harmonic Software package (2024) # ================================================== version: 1 @@ -29,21 +29,21 @@ handlers: class: logging.FileHandler level: INFO formatter: simple - filename: /logs/info.log + filename: info.log encoding: utf8 debug_file_handler: class: logging.FileHandler level: DEBUG formatter: simple - filename: /logs/debug.log + filename: debug.log encoding: utf8 critical_file_handler: class: logging.FileHandler level: CRITICAL formatter: simple - filename: /logs/critical.log + filename: critical.log encoding: utf8 loggers: diff --git a/harmonic/logs.py b/harmonic/logs.py index 4f31d962..87d3fcde 100644 --- a/harmonic/logs.py +++ b/harmonic/logs.py @@ -1,15 +1,16 @@ import os import logging.config import logging +from pathlib import Path import yaml import harmonic -import colorlog + def setup_logging(custom_yaml_path=None, default_level=logging.DEBUG): """initialise and configure logging. - - Should be called at the beginning of code to initialise and configure the - desired logging level. Logging levels can be ints in [0,50] where 10 is + + Should be called at the beginning of code to initialise and configure the + desired logging level. Logging levels can be ints in [0,50] where 10 is debug logging and 50 is critical logging. Args: @@ -24,35 +25,21 @@ def setup_logging(custom_yaml_path=None, default_level=logging.DEBUG): ValueError: Raised if logging.yaml is not in ./logs/ directory. """ - if custom_yaml_path == None: - path = os.path.join(os.path.dirname(os.path.dirname( - os.path.realpath(harmonic.__file__))) + '/logs/logging.yaml') - if custom_yaml_path != None: - path = custom_yaml_path - value = os.getenv('LOG_CFG', None) - if value: - path = value - if os.path.exists(path): - with open(path, 'rt') as f: - config = yaml.safe_load(f.read()) - if custom_yaml_path == None: - config['handlers']['info_file_handler']['filename'] = os.path.join( - os.path.dirname(os.path.dirname( - os.path.realpath(harmonic.__file__))) + '/logs/info.log') - config['handlers']['debug_file_handler']['filename'] = os.path.join( - os.path.dirname(os.path.dirname( - os.path.realpath(harmonic.__file__))) + '/logs/debug.log') - config['handlers']['critical_file_handler']['filename'] = os.path.join( - os.path.dirname(os.path.dirname( - os.path.realpath(harmonic.__file__))) + '/logs/critical.log') - config['handlers']['info_file_handler']['filename'] = os.path.join( - os.path.dirname(os.path.dirname( - os.path.realpath(harmonic.__file__))) + '/logs/info.log') - logging.config.dictConfig(config) + if "LOG_CFG" in os.environ: + path = Path(os.environ["LOG_CFG"]) + elif custom_yaml_path is None: + path = Path(harmonic.__file__).parent / "default-logging-config.yaml" else: - logging.basicConfig(level=default_level) - raise ValueError("Logging config pathway incorrect.") - critical_log('Using custom config from {}'.format(path)) + path = Path(custom_yaml_path) + if not path.exists(): + raise ValueError(f"Logging config path {path} does not exist.") + with open(path, "rt") as f: + config = yaml.safe_load(f.read()) + if custom_yaml_path is None: + config["handlers"]["info_file_handler"]["filename"] = "info.log" + config["handlers"]["debug_file_handler"]["filename"] = "debug.log" + config["handlers"]["critical_file_handler"]["filename"] = "critical.log" + logging.config.dictConfig(config) def debug_log(message): @@ -63,11 +50,12 @@ def debug_log(message): message: Message to log. """ - logger = logging.getLogger('Harmonic') + logger = logging.getLogger("Harmonic") logger.debug(message) + def warning_log(message): - """Log a warning (e.g. for internal code warnings such as large dynamic + """Log a warning (e.g. for internal code warnings such as large dynamic ranges). Args: @@ -75,9 +63,10 @@ def warning_log(message): message: Warning to log. """ - logger = logging.getLogger('Harmonic') + logger = logging.getLogger("Harmonic") logger.warning(message) + def critical_log(message): """Log a critical message (e.g. core code failures etc). @@ -86,11 +75,12 @@ def critical_log(message): message: Message to log. """ - logger = logging.getLogger('Harmonic') + logger = logging.getLogger("Harmonic") logger.critical(message) + def info_log(message): - """Log an information message (e.g. evidence value printing, run completion + """Log an information message (e.g. evidence value printing, run completion etc). Args: @@ -98,6 +88,5 @@ def info_log(message): message: Message to log. """ - logger = logging.getLogger('Harmonic') + logger = logging.getLogger("Harmonic") logger.info(message) - diff --git a/pyproject.toml b/pyproject.toml index 197ae6e4..2559e031 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools", "wheel", "numpy==1.23.1", "Cython==0.29.30"] +requires = ["setuptools", "wheel", "numpy", "Cython"] build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/setup.py b/setup.py index 449bf9f3..ee13723e 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,5 @@ -import sys import os import shutil -import setuptools from setuptools import setup, Extension from Cython.Distutils import build_ext from Cython.Build import cythonize @@ -48,7 +46,7 @@ def read_file(file): "Intended Audience :: Science/Research", ], name="harmonic", - version="1.2.2", + version="1.2.3", prefix=".", url="https://github.com/astro-informatics/harmonic", author="Jason D. McEwen, Alicja Polanska, Christopher G. R. Wallis, Matthew A. Price, Matthew M. Docherty & Contributors", @@ -59,6 +57,8 @@ def read_file(file): long_description_content_type="text/x-rst", long_description=long_description, packages=["harmonic"], + include_package_data=True, + package_data={"harmonic": ["default-logging-config.yaml"]}, cmdclass={"build_ext": build_ext}, ext_modules=cythonize( [