Warning: Can't use blame annotator:
svn blame failed on trunk/webapps/unifiedlogger/logging_service.py: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/webapps/unifiedlogger/logging_service.py @ 431

Revision 431, 1.7 KB checked in by jdalbey, 7 years ago (diff)

Add new files for prototype of unified logging service

RevLine 
1import cms_watcher, time, json
2# Unified Logging Service
3# jdalbey 7/6/2019
4
5
6# Load the sim time file and extract the seconds */
7def getSimTime():
8    with open ("../dynamicdata/sim_elapsedtime.json", 'r') as myfile:
9        jsonData=myfile.read()
10         
11    seconds = json.loads(jsonData)['elapsedtime']
12    # convert seconds to H:MM:SS
13    m, s = divmod(int(seconds), 60)
14    h, m = divmod(m, 60)
15    return  "%d:%02d:%02d" % (h, m, s)   
16
17def main():
18    # List of the available plugin modules
19    plugins = ["cms_watcher"]
20    #FOR each plugin LOOP
21    for plugin in plugins:
22        # dynamically load the setup function for this plugin
23        plugmodule = locals()[plugin]
24        setupfunc = getattr(plugmodule, 'setup')
25        #Call setup
26        setupfunc()
27    #END LOOP
28   
29    #DO Forever
30    while True:
31    #    Get simulation time
32        timeStamp = getSimTime()
33    #    Reset Output Buffer
34        output = ""
35    #    FOR each plugin LOOP
36        for plugin in plugins:
37            # dynamically load the setup function for this plugin
38            plugmodule = locals()[plugin]
39            comparefunc = getattr(plugmodule, 'compare')
40           
41    #        Run the plugin process returning new log entries
42            results = comparefunc()          # Look for changed messages
43    #    END LOOP
44    #    Append simulation time and the log entries to the Output Buffer
45        for item in results:
46            output += timeStamp + " " + item + "\n"
47    #    IF the Output Buffer has any contents THEN
48        if len(output) > 0:
49    #       Write (append) Output Buffer to unified log file
50            print output
51    #    END IF
52    #    Wait one second
53        time.sleep(1)
54
55#END DO
56if __name__ == "__main__":
57    main()
Note: See TracBrowser for help on using the repository browser.