Skip to content

Commit f517759

Browse files
authored
Fix problems with rel paths in logging files (ecmwf#742)
* Fixed relative path handling for logging files. * Adding default argument to _load_private_conf()
1 parent c3c5baa commit f517759

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/weathergen/utils/logger.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import sys
1414
from functools import cache
1515

16+
from weathergen.utils.config import _load_private_conf
17+
1618

1719
class ColoredRelPathFormatter(logging.Formatter):
1820
COLOR_CODES = {
@@ -53,6 +55,10 @@ def init_logger_per_stream(logger, stream_handle, output_streams):
5355
# path + file are specified as string or already path object
5456
assert type(ostr) is str or type(ostr) is pathlib.Path
5557
ofile = pathlib.Path(ostr)
58+
# make sure the path is independent of path where job is launched
59+
if not ofile.is_absolute():
60+
work_dir = pathlib.Path(_load_private_conf().get("path_shared_working_dir"))
61+
ofile = work_dir / ofile
5662
# make sure the parent directory exists
5763
pathlib.Path(ofile.parent).mkdir(parents=True, exist_ok=True)
5864
handler = logging.FileHandler(ofile)

0 commit comments

Comments
 (0)