Skip to content
Snippets Groups Projects
Commit efe82331 authored by Hans Fangohr's avatar Hans Fangohr
Browse files

Merge branch 'rename-log-variables' into 'rename-log-files'

Rename log related variables

See merge request mpsd-cs/mpsd-software-environments!38
parents 8a7371af cebc78aa
No related branches found
No related tags found
3 merge requests!38Rename log related variables,!37Update log names and variable names,!29Restructure log location
Pipeline #370257 passed
This commit is part of merge request !29. Comments created here will be created in the context of that merge request.
...@@ -153,8 +153,8 @@ def read_metadata_from_logfile(logfile: Union[str, Path]) -> dict: ...@@ -153,8 +153,8 @@ def read_metadata_from_logfile(logfile: Union[str, Path]) -> dict:
} }
def get_installer_log_file(mpsd_release: str, cmd: str, script_dir: str) -> str: def get_installer_log_file_path(mpsd_release: str, cmd: str, script_dir: str) -> str:
"""Get installer log file name.""" """Get installer log file path."""
# Get machine configs # Get machine configs
os.environ.get("MPSD_OS", "UNKNOWN_OS") os.environ.get("MPSD_OS", "UNKNOWN_OS")
mpsd_microarch = get_native_microarchitecture() mpsd_microarch = get_native_microarchitecture()
...@@ -175,7 +175,7 @@ def get_installer_log_file(mpsd_release: str, cmd: str, script_dir: str) -> str: ...@@ -175,7 +175,7 @@ def get_installer_log_file(mpsd_release: str, cmd: str, script_dir: str) -> str:
return installer_log_file return installer_log_file
def set_up_logging(loglevel="warning", filename=None): def set_up_logging(loglevel="warning", file_path=None):
"""Set up logging. """Set up logging.
This function sets up the logging configuration for the script. This function sets up the logging configuration for the script.
...@@ -190,7 +190,7 @@ def set_up_logging(loglevel="warning", filename=None): ...@@ -190,7 +190,7 @@ def set_up_logging(loglevel="warning", filename=None):
- warning (default): only print statements if something is unexpected - warning (default): only print statements if something is unexpected
- info (show more detailed progress) - info (show more detailed progress)
- debug (show very detailed output) - debug (show very detailed output)
filename : str file_path : str
- filename to save logging messages into - filename to save logging messages into
If loglevel is 'debug', save line numbers in log messages. If loglevel is 'debug', save line numbers in log messages.
...@@ -280,8 +280,8 @@ def set_up_logging(loglevel="warning", filename=None): ...@@ -280,8 +280,8 @@ def set_up_logging(loglevel="warning", filename=None):
logger.handlers = [shell_handler] logger.handlers = [shell_handler]
# if filename provided, write log messages to that file, too. # if filename provided, write log messages to that file, too.
if filename: if file_path:
file_handler = logging.FileHandler(filename) file_handler = logging.FileHandler(file_path)
# if we have a file, we write all information in there. # if we have a file, we write all information in there.
# We could change the level, for example restrict to only DEBUG and above with # We could change the level, for example restrict to only DEBUG and above with
# file_handler.setLevel(logging.DEBUG) # file_handler.setLevel(logging.DEBUG)
...@@ -305,9 +305,9 @@ def set_up_logging(loglevel="warning", filename=None): ...@@ -305,9 +305,9 @@ def set_up_logging(loglevel="warning", filename=None):
print_log.addHandler(ch) print_log.addHandler(ch)
# if filename provided, write output of print_log to that file, too # if filename provided, write output of print_log to that file, too
if filename: if file_path:
# create, format and add file handler # create, format and add file handler
fh = logging.FileHandler(filename) fh = logging.FileHandler(file_path)
fh.setFormatter(formatter) fh.setFormatter(formatter)
print_log.addHandler(fh) print_log.addHandler(fh)
...@@ -316,7 +316,7 @@ def set_up_logging(loglevel="warning", filename=None): ...@@ -316,7 +316,7 @@ def set_up_logging(loglevel="warning", filename=None):
# #
logging.debug( logging.debug(
f"Logging has been setup, loglevel={loglevel.upper()} " f"Logging has been setup, loglevel={loglevel.upper()} "
+ f"{filename=} {rich_available=}" + f"{file_path=} {rich_available=}"
) )
...@@ -790,7 +790,7 @@ def install_environment( ...@@ -790,7 +790,7 @@ def install_environment(
mpsd_release, mpsd_microarch, "install", toolchain=toolchain mpsd_release, mpsd_microarch, "install", toolchain=toolchain
) )
build_log_folder = release_base_dir / "logs" build_log_folder = release_base_dir / "logs"
build_log_file = build_log_folder / build_log_file_name build_log_path = build_log_folder / build_log_file_name
# if logs folder dosent exist, create it # if logs folder dosent exist, create it
if not os.path.exists(build_log_folder): if not os.path.exists(build_log_folder):
os.makedirs(build_log_folder) os.makedirs(build_log_folder)
...@@ -801,7 +801,7 @@ def install_environment( ...@@ -801,7 +801,7 @@ def install_environment(
setup_log_cmd( setup_log_cmd(
mpsd_release, mpsd_release,
script_dir, script_dir,
msg=f"installing {toolchain} and logging at {build_log_file}", msg=f"installing {toolchain} and logging at {build_log_path}",
) )
setup_log_cmd( setup_log_cmd(
mpsd_release, mpsd_release,
...@@ -813,7 +813,7 @@ def install_environment( ...@@ -813,7 +813,7 @@ def install_environment(
) )
run( run(
f"bash {spack_setup_script} {' '.join(install_flags)} {toolchain} 2>&1 " f"bash {spack_setup_script} {' '.join(install_flags)} {toolchain} 2>&1 "
f"| tee -a {build_log_file} ", f"| tee -a {build_log_path} ",
shell=True, shell=True,
check=True, check=True,
) )
...@@ -918,7 +918,8 @@ def main(): ...@@ -918,7 +918,8 @@ def main():
script_dir = Path(os.path.dirname(os.path.realpath(__file__))) script_dir = Path(os.path.dirname(os.path.realpath(__file__)))
set_up_logging( set_up_logging(
args.loglevel, get_installer_log_file(args.release, args.action, script_dir) args.loglevel,
get_installer_log_file_path(args.release, args.action, script_dir),
) )
# Check the command and run related function # Check the command and run related function
......
...@@ -14,7 +14,7 @@ mod = importlib.import_module("mpsd-software-environment") ...@@ -14,7 +14,7 @@ mod = importlib.import_module("mpsd-software-environment")
# set loglevel to debug - useful for understanding problems. # set loglevel to debug - useful for understanding problems.
# (if the tests pass, pytest doesn't show any output) # (if the tests pass, pytest doesn't show any output)
mod.set_up_logging(loglevel="debug", filename="tests.log") mod.set_up_logging(loglevel="debug", file_path="tests.log")
logging.debug(f"We have set up logging from {__file__}") logging.debug(f"We have set up logging from {__file__}")
...@@ -273,7 +273,7 @@ def test_install_environment_zlib(): ...@@ -273,7 +273,7 @@ def test_install_environment_zlib():
# install global_generic toolchain # install global_generic toolchain
mod.set_up_logging( mod.set_up_logging(
"WARNING", "WARNING",
mod.get_installer_log_file(mpsd_release_to_test, "install", script_dir), mod.get_installer_log_file_path(mpsd_release_to_test, "install", script_dir),
) )
mod.install_environment( mod.install_environment(
mpsd_release=mpsd_release_to_test, mpsd_release=mpsd_release_to_test,
...@@ -328,7 +328,7 @@ def test_install_environment_zlib(): ...@@ -328,7 +328,7 @@ def test_install_environment_zlib():
importlib.reload(mod) importlib.reload(mod)
mod.set_up_logging( mod.set_up_logging(
"WARNING", "WARNING",
mod.get_installer_log_file(mpsd_release_to_test, "install", script_dir), mod.get_installer_log_file_path(mpsd_release_to_test, "install", script_dir),
) )
mod.install_environment( mod.install_environment(
mpsd_release=mpsd_release_to_test, mpsd_release=mpsd_release_to_test,
...@@ -349,7 +349,7 @@ def test_metadata_logging(tmp_path): ...@@ -349,7 +349,7 @@ def test_metadata_logging(tmp_path):
# Test that the metadata is logged correctly # Test that the metadata is logged correctly
filename = tmp_path / "test-metadata.log" filename = tmp_path / "test-metadata.log"
print(f"Writing to {filename}") print(f"Writing to {filename}")
mod.set_up_logging(loglevel="debug", filename=filename) mod.set_up_logging(loglevel="debug", file_path=filename)
# our test data # our test data
keys = ["important_key", "important_key2"] keys = ["important_key", "important_key2"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment