Diff of /utilities/logUtils.py [000000] .. [a18f15]

Switch to unified view

a b/utilities/logUtils.py
1
import json
2
import csv
3
4
def LOG2CSV(datalist, csv_file, flag = 'a'):
5
    '''
6
    datalist: List of elements to be written
7
    '''
8
    with open(csv_file, flag) as csvFile:
9
        writer = csv.writer(csvFile)
10
        writer.writerow(datalist)
11
    csvFile.close()
12
13
def LOG2TXT(text, file_path, flag = 'a', console= True):
14
    '''
15
    text: python object with stats to be logged
16
    '''
17
    text = str(text)
18
    with open(file_path, 'a', buffering=1) as txt_file:
19
        if console: print(text)
20
        print(text, file=txt_file)
21
22
23
def LOG2DICTXT(dic, file_path, flag = 'a', console= True):
24
    '''
25
    stats: dictionary object with stats to be logged
26
    '''
27
    with open(file_path, 'a', buffering=1) as txt_file:
28
        if console: print(json.dumps(dic))
29
        print(json.dumps(dic), file=txt_file)
30
31