From b0bd102d44ce382215cff45378104b42e84adde2 Mon Sep 17 00:00:00 2001 From: Paco Hope Date: Wed, 4 Oct 2023 13:55:02 -0400 Subject: [PATCH] added debug logging --- src/hetrixtools_freebsd/cli.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/hetrixtools_freebsd/cli.py b/src/hetrixtools_freebsd/cli.py index 2bcd21b..64fa38c 100644 --- a/src/hetrixtools_freebsd/cli.py +++ b/src/hetrixtools_freebsd/cli.py @@ -21,8 +21,8 @@ __license__ = "BSD-3-Clause" _logger = logging.getLogger(__name__) class Update: - def __init__(self): - self.version = "" + def __init__(self, logger): + self.version = "2.0.5" self.SID = "" self.agent = "" self.user = "" @@ -65,6 +65,7 @@ class Update: self.cust = "" self.rps1 = "" self.rps2 = "" + self.logger = logger def callCommand(self, command=[]): """Given a command and args in a list, run the command and return its @@ -84,9 +85,9 @@ class Update: self.cpumodel = self.callCommand(['sysctl', 'hw.model']).split("\n")[0].split(" ")[1] self.cpumodel = base64.b64encode(self.cpumodel.encode()).decode('utf-8') - print(f"cpusockets = {self.cpusockets}, cpuspeed = {self.cpuspeed}") - print(f"cputhreads = {self.cputhreads}, cpucores = {self.cpucores}") - print(f"cpumodel = {self.cpumodel}") + self.logger.debug(f"cpusockets = {self.cpusockets}, cpuspeed = {self.cpuspeed}") + self.logger.debug(f"cputhreads = {self.cputhreads}, cpucores = {self.cpucores}") + self.logger.debug(f"cpumodel = {self.cpumodel}") def toJsonString(self): """Return the object as a JSON string.""" @@ -141,10 +142,12 @@ class Update: def go(): """Run the command.""" - update = Update() + update = Update(_logger) + _logger.info(f"Starting to fetch results") update.getCPUInfo() + _logger.info(f"Done fetching results") output = update.toJsonString() - print(f"{output}") + _logger.debug(f"{output}") def parse_args(args): """Parse command line parameters @@ -198,10 +201,10 @@ def main(args): """ args = parse_args(args) setup_logging(args.loglevel) - _logger.debug("Starting crazy calculations...") + _logger.debug("Log level DEBUG") + _logger.info("Log level INFO") go() - print("Done") - _logger.info("Script ends here") + _logger.info("Done.") def run():