gui: add arg for saving log to a file
This commit is contained in:
parent
1896e2534b
commit
1111967a7b
|
@ -39,10 +39,8 @@ FLOAT_REGEX = re.compile(r'(?P<number>[+-]?((((\d+(\.\d*)?)|(\d*\.\d+))([eE][+-]
|
|||
def get_argparser():
|
||||
parser = argparse.ArgumentParser(description="ARTIQ master")
|
||||
|
||||
parser.add_argument("--connect", default=None, action="store_true",
|
||||
help="Automatically connect to the specified Thermostat in IP:port format")
|
||||
parser.add_argument('IP', metavar="ip", default=None, nargs='?')
|
||||
parser.add_argument('PORT', metavar="port", default=None, nargs='?')
|
||||
parser.add_argument("--log-file", default="", nargs="?",
|
||||
help="Store logs into a file; Set the base filename")
|
||||
parser.add_argument("-l", "--log", dest="logLevel", choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
|
||||
help="Set the logging level")
|
||||
|
||||
|
@ -951,6 +949,17 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||
|
||||
async def coro_main():
|
||||
args = get_argparser().parse_args()
|
||||
if args.log_file or args.log_file is None:
|
||||
filename = args.log_file
|
||||
if filename is None:
|
||||
time = datetime.now()
|
||||
filename = f"{time.year}-{time.day}-{time.month}-{time.hour}:{time.minute}:{time.second}.log"
|
||||
logging.basicConfig(filename=filename,
|
||||
filemode='a',
|
||||
format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
|
||||
datefmt='%Y/%d/%m %H:%M:%S',
|
||||
level=logging.INFO)
|
||||
|
||||
if args.logLevel:
|
||||
logging.basicConfig(level=getattr(logging, args.logLevel))
|
||||
|
||||
|
|
Loading…
Reference in New Issue