From 37d8374a0ef6a743c2c4999843b0a65ac4c5adae Mon Sep 17 00:00:00 2001 From: Chuck SmileyRekiere Date: Fri, 13 Nov 2020 11:43:48 -0700 Subject: [PATCH] cisco_wifi_ctl.py : added the ability to append logging to an existing file This was needed since lf_cisco_power.py and other files that use cisco_wifi_ctl.py will need to pass in a log file. --- cisco_wifi_ctl.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cisco_wifi_ctl.py b/cisco_wifi_ctl.py index 78e81c1c..15e05d5e 100755 --- a/cisco_wifi_ctl.py +++ b/cisco_wifi_ctl.py @@ -99,6 +99,7 @@ def main(): parser.add_argument("-s", "--scheme", type=str, choices=["serial", "ssh", "telnet"], help="Connect via serial, ssh or telnet") parser.add_argument("-t", "--tty", type=str, help="tty serial device") parser.add_argument("-l", "--log", type=str, help="logfile for messages, stdout means output to console",default="stdout") + parser.add_argument("--append", action='store_true', help="--append append to logfile file") #parser.add_argument("-r", "--radio", type=str, help="select radio") parser.add_argument("-w", "--wlan", type=str, help="wlan name") parser.add_argument("-i", "--wlanID", type=str, help="wlan ID") @@ -124,6 +125,7 @@ def main(): user = args.user passwd = args.passwd logfile = args.log + append = args.append if (args.band != None): band = args.band if (band == "abgn"): @@ -141,11 +143,14 @@ def main(): file_handler = None if (logfile is not None): if (logfile != "stdout"): - file_handler = logging.FileHandler(logfile, "w") + if append: + file_handler = logging.FileHandler(logfile, "a") + else: + file_handler = logging.FileHandler(logfile, "w") file_handler.setLevel(logging.DEBUG) file_handler.setFormatter(formatter) logg.addHandler(file_handler) - logging.basicConfig(format=FORMAT, handlers=[file_handler]) + logg.addHandler(logging.StreamHandler(sys.stdout)) else: # stdout logging logging.basicConfig(format=FORMAT, handlers=[console_handler])