Coverage for mflog/log.py: 0%

20 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-10-08 09:20 +0000

1#!/bin/env python3 

2 

3import argparse 

4from mflog import get_logger 

5 

6 

7def main(): 

8 parser = argparse.ArgumentParser("log a message with standard metwork " 

9 "logging system") 

10 parser.add_argument('--application-name', '-a', action="store", 

11 default="default", help="application name") 

12 parser.add_argument('LEVEL', action='store', 

13 help="Log level", 

14 choices=['ERROR', 'CRITICAL', 'WARNING', 'INFO', 

15 'DEBUG']) 

16 parser.add_argument('MESSAGE', action='store', help="message to log") 

17 options = parser.parse_args() 

18 

19 logger = get_logger(options.application_name) 

20 if options.LEVEL == 'DEBUG': 

21 logger.debug(options.MESSAGE) 

22 elif options.LEVEL == 'INFO': 

23 logger.info(options.MESSAGE) 

24 elif options.LEVEL == 'WARNING': 

25 logger.warning(options.MESSAGE) 

26 elif options.LEVEL == 'CRITICAL': 

27 logger.critical(options.MESSAGE) 

28 elif options.LEVEL == 'ERROR': 

29 logger.error(options.MESSAGE) 

30 else: 

31 raise Exception("Bad message level: %s", options.LEVEL) 

32 

33 

34if __name__ == "__main__": 

35 main()