You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

51 lines
1.5 KiB

#!/usr/bin/env python3.7
import logging
import Server
def initLogging(logFileName: str) -> None:
"""
Initialise the logging method
"""
logFormatter = logging.Formatter(
fmt="[%(asctime)s][%(levelname)s] %(message)s",
datefmt='%d-%b-%y %H:%M:%S')
rootLogger = logging.getLogger()
fileHandler = logging.FileHandler(logFileName, mode='a')
fileHandler.setFormatter(logFormatter)
rootLogger.addHandler(fileHandler)
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(logFormatter)
rootLogger.addHandler(consoleHandler)
rootLogger.setLevel(logging.INFO)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('host',
metavar='HOST',
help='IP to listen.',
type=str)
parser.add_argument('port',
metavar='PORT',
help='Port to listen.',
type=int)
parser.add_argument('--logFile',
metavar='LOGPATH',
help='Path to log file, default is log.txt',
type=str,
required=False,
default='log.txt')
args = parser.parse_args()
initLogging(args.logFile)
try:
Server.Server(args.host, args.port).run()
except KeyboardInterrupt:
logging.info('Stopped by user input')