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

  1. #!/usr/bin/env python3.7
  2. import logging
  3. import Server
  4. def initLogging(logFileName: str) -> None:
  5. """
  6. Initialise the logging method
  7. """
  8. logFormatter = logging.Formatter(
  9. fmt="[%(asctime)s][%(levelname)s] %(message)s",
  10. datefmt='%d-%b-%y %H:%M:%S')
  11. rootLogger = logging.getLogger()
  12. fileHandler = logging.FileHandler(logFileName, mode='a')
  13. fileHandler.setFormatter(logFormatter)
  14. rootLogger.addHandler(fileHandler)
  15. consoleHandler = logging.StreamHandler()
  16. consoleHandler.setFormatter(logFormatter)
  17. rootLogger.addHandler(consoleHandler)
  18. rootLogger.setLevel(logging.INFO)
  19. if __name__ == "__main__":
  20. import argparse
  21. parser = argparse.ArgumentParser()
  22. parser.add_argument('host',
  23. metavar='HOST',
  24. help='IP to listen.',
  25. type=str)
  26. parser.add_argument('port',
  27. metavar='PORT',
  28. help='Port to listen.',
  29. type=int)
  30. parser.add_argument('--logFile',
  31. metavar='LOGPATH',
  32. help='Path to log file, default is log.txt',
  33. type=str,
  34. required=False,
  35. default='log.txt')
  36. args = parser.parse_args()
  37. initLogging(args.logFile)
  38. try:
  39. Server.Server(args.host, args.port).run()
  40. except KeyboardInterrupt:
  41. logging.info('Stopped by user input')