-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogger.py
More file actions
52 lines (42 loc) · 1.63 KB
/
logger.py
File metadata and controls
52 lines (42 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sys
import time
import os
import uuid
import globals
script_dir = os.path.dirname(__file__)
logs_dir = script_dir + '/logs/'
class Logger:
def __init__(self):
self.check_log_dir()
if ('session_id' in globals.configs) is False:
print("session_id is null")
globals.configs['session_id'] = str(uuid.uuid1())
@staticmethod
def set_log(data, is_print_to_console=False):
if is_print_to_console:
print(data)
session_id = globals.configs['session_id']
abs_file_path = os.path.join(logs_dir, 'log_' + session_id + '.txt')
with open(abs_file_path, 'a') as the_file:
the_file.write(str(time.strftime('%c')) + " : " + str(data))
the_file.write('\n')
@staticmethod
def set_error_log(data, is_print_to_console=False):
if is_print_to_console:
print("set_error_log() Error:" + data)
session_id = globals.configs['session_id']
abs_file_path = os.path.join(logs_dir, 'log_' + session_id + '.txt')
with open(abs_file_path, 'a') as the_file:
the_file.write(str(time.strftime('%c')) + " : " + str(data))
the_file.write('\n')
@staticmethod
def set_memory_log(data):
session_id = globals.configs['session_id']
abs_file_path = os.path.join(logs_dir, 'log_' + session_id + '.txt')
with open(abs_file_path, 'a') as the_file:
the_file.write(str(time.strftime('%c')) + " : " + str(data))
the_file.write('\n')
@staticmethod
def check_log_dir():
if os.path.isdir(logs_dir) is not True:
os.mkdir(logs_dir)