Changeset 439 in tmcsimulator for trunk/webapps/unifiedlogger/logging_service.py


Ignore:
Timestamp:
07/11/2019 02:45:25 PM (7 years ago)
Author:
jdalbey
Message:

setup wing project for logging service python files. Add config file for file paths.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/webapps/unifiedlogger/logging_service.py

    r433 r439  
    1 import cms_watcher, cad_watcher, time, json 
     1import cms_watcher, cad_watcher, time, json, ConfigParser 
    22# Unified Logging Service 
    33# jdalbey 7/6/2019 
    44 
     5outputFilename = "unifiedlog.csv" 
    56 
    67# Load the sim time file and extract the seconds */ 
    78def getSimTime(): 
    8     with open ("../dynamicdata/sim_elapsedtime.json", 'r') as myfile: 
     9    with open ("webapps/dynamicdata/sim_elapsedtime.json", 'r') as myfile: 
    910        jsonData=myfile.read() 
    1011          
     
    1516    return  "%d:%02d:%02d" % (h, m, s)     
    1617 
    17 def main(): 
     18def startup(): 
     19    # get path to output file from configuration 
     20    config = ConfigParser.ConfigParser() 
     21    config.read('config/logging_service.cfg') 
     22    logfilepath  = config.get('Paths', 'UnifiedLogPath') 
     23     
    1824    # Delete any previously existing output file 
    19     f = open("../dynamicdata/unifiedlog.html", "w") 
    20     startHTML = "<HTML><HEAD><meta http-equiv=\"refresh\" content=\"5\" /></HEAD><BODY><PRE>" 
    21     f.write(startHTML); 
     25    f = open(logfilepath + outputFilename, "w") 
    2226    f.close()             
    2327    # List of the available plugin modules  
     
    5155                trimmed_item = item.strip() 
    5256                if len(trimmed_item) > 0: 
    53                     output += timeStamp + " " + trimmed_item + "\n" 
     57                    output += timeStamp + ", " + trimmed_item + "\n" 
    5458    #    END LOOP 
    5559    #    IF the Output Buffer has any contents THEN 
    5660        if len(output) > 0: 
    57     #       Write (append) Output Buffer to unified log file  
     61    #       Write (append) Output Buffer to unified log file as CSV 
     62    #       Assumes fields don't contain commas  
    5863            print output, 
    59             f = open("../dynamicdata/unifiedlog.html", "a") 
     64            f = open(logfilepath + outputFilename, "a") 
    6065            f.write(output) 
    6166            f.close()             
    6267    #    END IF 
    63     #    Wait one second 
    64         time.sleep(1) 
     68    #    Wait five seconds 
     69        time.sleep(5) 
    6570 
    6671#END DO 
    67 if __name__ == "__main__": 
    68     main() 
     72 
     73if __name__ == '__main__': 
     74    startup() 
Note: See TracChangeset for help on using the changeset viewer.