added debug logging

main
Paco Hope 2023-10-04 13:55:02 -04:00
parent 1d5cb738e2
commit b0bd102d44
1 changed files with 13 additions and 10 deletions

View File

@ -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():