Skip to content

Commit 9726ce2

Browse files
authored
Merge pull request #306 from astro-informatics/logging_update
Update logging and unpin numpy and cython versions in pyproject.toml
2 parents 6e29129 + 4040ada commit 9726ce2

File tree

5 files changed

+38
-49
lines changed

5 files changed

+38
-49
lines changed

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
author = "Jason D. McEwen, Christopher G. R. Wallis, Matthew A. Price, Matthew M. Docherty, Alicja Polanska"
2626

2727
# The short X.Y version
28-
version = "1.2.2"
28+
version = "1.2.3"
2929
# The full version, including alpha/beta/rc tags
30-
release = "1.2.2"
30+
release = "1.2.3"
3131

3232

3333
# -- General configuration ---------------------------------------------------

logs/logging.yaml renamed to harmonic/default-logging-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ==================================================
2-
# Logging setup for Harmonic Software package (2018)
2+
# Logging setup for Harmonic Software package (2024)
33
# ==================================================
44

55
version: 1
@@ -29,21 +29,21 @@ handlers:
2929
class: logging.FileHandler
3030
level: INFO
3131
formatter: simple
32-
filename: /logs/info.log
32+
filename: info.log
3333
encoding: utf8
3434

3535
debug_file_handler:
3636
class: logging.FileHandler
3737
level: DEBUG
3838
formatter: simple
39-
filename: /logs/debug.log
39+
filename: debug.log
4040
encoding: utf8
4141

4242
critical_file_handler:
4343
class: logging.FileHandler
4444
level: CRITICAL
4545
formatter: simple
46-
filename: /logs/critical.log
46+
filename: critical.log
4747
encoding: utf8
4848

4949
loggers:

harmonic/logs.py

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import os
22
import logging.config
33
import logging
4+
from pathlib import Path
45
import yaml
56
import harmonic
6-
import colorlog
7+
78

89
def setup_logging(custom_yaml_path=None, default_level=logging.DEBUG):
910
"""initialise and configure logging.
10-
11-
Should be called at the beginning of code to initialise and configure the
12-
desired logging level. Logging levels can be ints in [0,50] where 10 is
11+
12+
Should be called at the beginning of code to initialise and configure the
13+
desired logging level. Logging levels can be ints in [0,50] where 10 is
1314
debug logging and 50 is critical logging.
1415
1516
Args:
@@ -24,35 +25,21 @@ def setup_logging(custom_yaml_path=None, default_level=logging.DEBUG):
2425
ValueError: Raised if logging.yaml is not in ./logs/ directory.
2526
2627
"""
27-
if custom_yaml_path == None:
28-
path = os.path.join(os.path.dirname(os.path.dirname(
29-
os.path.realpath(harmonic.__file__))) + '/logs/logging.yaml')
30-
if custom_yaml_path != None:
31-
path = custom_yaml_path
32-
value = os.getenv('LOG_CFG', None)
33-
if value:
34-
path = value
35-
if os.path.exists(path):
36-
with open(path, 'rt') as f:
37-
config = yaml.safe_load(f.read())
38-
if custom_yaml_path == None:
39-
config['handlers']['info_file_handler']['filename'] = os.path.join(
40-
os.path.dirname(os.path.dirname(
41-
os.path.realpath(harmonic.__file__))) + '/logs/info.log')
42-
config['handlers']['debug_file_handler']['filename'] = os.path.join(
43-
os.path.dirname(os.path.dirname(
44-
os.path.realpath(harmonic.__file__))) + '/logs/debug.log')
45-
config['handlers']['critical_file_handler']['filename'] = os.path.join(
46-
os.path.dirname(os.path.dirname(
47-
os.path.realpath(harmonic.__file__))) + '/logs/critical.log')
48-
config['handlers']['info_file_handler']['filename'] = os.path.join(
49-
os.path.dirname(os.path.dirname(
50-
os.path.realpath(harmonic.__file__))) + '/logs/info.log')
51-
logging.config.dictConfig(config)
28+
if "LOG_CFG" in os.environ:
29+
path = Path(os.environ["LOG_CFG"])
30+
elif custom_yaml_path is None:
31+
path = Path(harmonic.__file__).parent / "default-logging-config.yaml"
5232
else:
53-
logging.basicConfig(level=default_level)
54-
raise ValueError("Logging config pathway incorrect.")
55-
critical_log('Using custom config from {}'.format(path))
33+
path = Path(custom_yaml_path)
34+
if not path.exists():
35+
raise ValueError(f"Logging config path {path} does not exist.")
36+
with open(path, "rt") as f:
37+
config = yaml.safe_load(f.read())
38+
if custom_yaml_path is None:
39+
config["handlers"]["info_file_handler"]["filename"] = "info.log"
40+
config["handlers"]["debug_file_handler"]["filename"] = "debug.log"
41+
config["handlers"]["critical_file_handler"]["filename"] = "critical.log"
42+
logging.config.dictConfig(config)
5643

5744

5845
def debug_log(message):
@@ -63,21 +50,23 @@ def debug_log(message):
6350
message: Message to log.
6451
6552
"""
66-
logger = logging.getLogger('Harmonic')
53+
logger = logging.getLogger("Harmonic")
6754
logger.debug(message)
6855

56+
6957
def warning_log(message):
70-
"""Log a warning (e.g. for internal code warnings such as large dynamic
58+
"""Log a warning (e.g. for internal code warnings such as large dynamic
7159
ranges).
7260
7361
Args:
7462
7563
message: Warning to log.
7664
7765
"""
78-
logger = logging.getLogger('Harmonic')
66+
logger = logging.getLogger("Harmonic")
7967
logger.warning(message)
8068

69+
8170
def critical_log(message):
8271
"""Log a critical message (e.g. core code failures etc).
8372
@@ -86,18 +75,18 @@ def critical_log(message):
8675
message: Message to log.
8776
8877
"""
89-
logger = logging.getLogger('Harmonic')
78+
logger = logging.getLogger("Harmonic")
9079
logger.critical(message)
9180

81+
9282
def info_log(message):
93-
"""Log an information message (e.g. evidence value printing, run completion
83+
"""Log an information message (e.g. evidence value printing, run completion
9484
etc).
9585
9686
Args:
9787
9888
message: Message to log.
9989
10090
"""
101-
logger = logging.getLogger('Harmonic')
91+
logger = logging.getLogger("Harmonic")
10292
logger.info(message)
103-

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[build-system]
2-
requires = ["setuptools", "wheel", "numpy==1.23.1", "Cython==0.29.30"]
2+
requires = ["setuptools", "wheel", "numpy", "Cython"]
33
build-backend = "setuptools.build_meta"

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import sys
21
import os
32
import shutil
4-
import setuptools
53
from setuptools import setup, Extension
64
from Cython.Distutils import build_ext
75
from Cython.Build import cythonize
@@ -48,7 +46,7 @@ def read_file(file):
4846
"Intended Audience :: Science/Research",
4947
],
5048
name="harmonic",
51-
version="1.2.2",
49+
version="1.2.3",
5250
prefix=".",
5351
url="https://github.com/astro-informatics/harmonic",
5452
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):
5957
long_description_content_type="text/x-rst",
6058
long_description=long_description,
6159
packages=["harmonic"],
60+
include_package_data=True,
61+
package_data={"harmonic": ["default-logging-config.yaml"]},
6262
cmdclass={"build_ext": build_ext},
6363
ext_modules=cythonize(
6464
[

0 commit comments

Comments
 (0)