Merge test folder of test branch
[iotivity.git] / test / test_manager / ite / multi_logger.py
1 #!/usr/bin/python3
2
3 import os
4 import sys
5 import datetime
6 import traceback
7 import logging
8
9 global logger
10
11 logger = logging.getLogger('scope.name')
12 logger.setLevel('INFO')
13
14 global log_file_name
15 log_file_name = ''
16
17 def set_file_handler(module, platform_type, verdict_path):
18     tokens = verdict_path.split(os.sep)
19     global log_file_name
20     log_file_name = 'test_manager_{}_{}.log'.format(module, platform_type)
21     if len(tokens) > 1:
22         log_file_name = os.sep.join(tokens[0:-1]) + os.sep + log_file_name
23
24     file_log_handler = logging.FileHandler(log_file_name)
25     logger.addHandler(file_log_handler)
26
27 def print_to_file(*msgs):
28     global log_file_name
29
30     if logger:
31         for msg in msgs:
32             timestring = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
33             logger.info(timestring + ' ' + str(msg))
34
35 def print_runner_output(*msgs):
36     global log_file_name
37
38     for msg in msgs:
39         print (msg)
40
41     print_to_file(msgs)
42
43 def show_exeception():
44     #print_runner_output("Unexpected error:", sys.exc_info()[0])
45     traceback.print_exc(file=sys.stdout)
46     if logger:
47         logger.info(traceback.print_exc())