Merge pull request 'Starting to implement logs' (#796) from Qubasa-main into main

This commit is contained in:
clan-bot
2024-02-02 05:07:39 +00:00
10 changed files with 74 additions and 23 deletions

View File

@@ -117,10 +117,10 @@ def main() -> None:
parser.print_help()
if args.debug:
setup_logging(logging.DEBUG)
setup_logging(logging.DEBUG, root_log_name=__name__.split(".")[0])
log.debug("Debug log activated")
else:
setup_logging(logging.INFO)
setup_logging(logging.INFO, root_log_name=__name__.split(".")[0])
if not hasattr(args, "func"):
return

View File

@@ -66,9 +66,9 @@ def get_caller() -> str:
return ret
def setup_logging(level: Any) -> None:
def setup_logging(level: Any, root_log_name: str = __name__.split(".")[0]) -> None:
# Get the root logger and set its level
main_logger = logging.getLogger("clan_cli")
main_logger = logging.getLogger(root_log_name)
main_logger.setLevel(level)
# Create and add the default handler

View File

@@ -102,7 +102,6 @@ class Machine:
system = config["system"]
attr = f'clanInternals.machines."{system}".{self.name}.{attr}'
print(f"attr: {attr}")
if attr in self.eval_cache and not refresh:
return self.eval_cache[attr]
@@ -115,9 +114,8 @@ class Machine:
else:
flake = self.flake
print(f"evaluating {flake}#{attr}")
cmd = nix_eval([f"{flake}#{attr}"])
print(f"cmd: {cmd}")
output = run(cmd).stdout.strip()
self.eval_cache[attr] = output
return output