From dcd3f2a108121e509778f566af8d3fd5ad17d696 Mon Sep 17 00:00:00 2001 From: Matthew Stidham Date: Wed, 24 Feb 2021 11:23:53 -0800 Subject: [PATCH] Added a new logging function using the python logging function into lfcli base and updating realm to use the new function Signed-off-by: Matthew Stidham --- py-json/LANforge/lfcli_base.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/py-json/LANforge/lfcli_base.py b/py-json/LANforge/lfcli_base.py index 77c71ac6..4c2a0331 100644 --- a/py-json/LANforge/lfcli_base.py +++ b/py-json/LANforge/lfcli_base.py @@ -16,6 +16,7 @@ from LANforge import LFRequest import LANforge.LFRequest import csv import pandas as pd +import os class LFCliBase: @@ -369,6 +370,7 @@ class LFCliBase: if duration >= 300: print("Could not connect to LANforge GUI") sys.exit(1) + #return ALL messages in list form def get_result_list(self): return self.test_results @@ -457,11 +459,38 @@ class LFCliBase: # print("lfclibase::self.proxy: ") # pprint.pprint(self.proxy) - def logg(self, level="debug", mesg=None): + + def logg2(self, level="debug", mesg=None): if (mesg is None) or (mesg == ""): return print("[{level}]: {msg}".format(level=level, msg=mesg)) + def logg(self, + level=None, + mesg=None, + filename=None, + scriptname=None): + if (mesg is None) or (mesg == "") or (level is None): + return + userhome=os.path.expanduser('~') + session = str(datetime.datetime.now().strftime("%Y-%m-%d-%H-h-%M-m-%S-s")).replace(':','-') + if filename == None: + try: + os.mkdir("%s/report-data/%s" % (userhome, session)) + except: + pass + filename = ("%s/report-data/%s/%s.log" % (userhome,session,scriptname)) + import logging + logging.basicConfig(filename=filename, level=logging.DEBUG) + if level == "debug": + logging.debug(mesg) + elif level == "info": + logging.info(mesg) + elif level == "warning": + logging.warning(mesg) + elif level == "error": + logging.error(mesg) + # This style of Action subclass for argparse can't do much unless we incorporate # our argparse as a member of LFCliBase. Then we can do something like automatically # parse our proxy string without using _init_ arguments