Skip to content

Commit

Permalink
Merge pull request #306 from astro-informatics/logging_update
Browse files Browse the repository at this point in the history
Update logging and unpin numpy and cython versions in pyproject.toml
  • Loading branch information
CosmoMatt authored Sep 26, 2024
2 parents 6e29129 + 4040ada commit 9726ce2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 49 deletions.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions logs/logging.yaml → harmonic/default-logging-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ==================================================
# Logging setup for Harmonic Software package (2018)
# Logging setup for Harmonic Software package (2024)
# ==================================================

version: 1
Expand Down Expand Up @@ -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:
Expand Down
67 changes: 28 additions & 39 deletions harmonic/logs.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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):
Expand All @@ -63,21 +50,23 @@ 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:
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).
Expand All @@ -86,18 +75,18 @@ 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:
message: Message to log.
"""
logger = logging.getLogger('Harmonic')
logger = logging.getLogger("Harmonic")
logger.info(message)

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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(
[
Expand Down

0 comments on commit 9726ce2

Please sign in to comment.