# $language = "Python" # $interface = "1.0" # ShowLoggingStatusAndStats.py # # Last Modified: # 30 Mar, 2020: # - Initial revision # # Description: # Displays logging status and stats in the status bar. # # For examples: # # Logging: Off # # Logging: On (1,247,800 lines - 67.70 MB) # # Hint: Run from a button bar; OK. Better if it's run # as a Logon Script as configured in the Logon # Actions section of Session Options for your # saved session. import os crt.Screen.Synchronous = False def main(): # refresh status every 1000 milliseconds nRefreshRateMs = 1000 strLastLoggingStatus = "" strCurLogStatus = "" try: while True: #check current status if crt.Session.Connected: if crt.Session.Logging: if strLastLoggingStatus <> "on": strLastLoggingStatus = "on" strLogFilePath = crt.Session.LogFileName nLines = 0 for strLine in open(strLogFilePath, 'r'): nLines += 1 objStats = os.stat(strLogFilePath) nBytes = objStats.st_size if nBytes <= 1023: strBytes = "{} B".format(nBytes) elif nBytes <= 1048575: strBytes = "{0:.2f} KB".format(nBytes/1024.00) else: strBytes = "{0:.2f} MB".format(nBytes/1024.00/1024.00) strCurLogStatus = "Logging: On ({:,} lines - {})".format( nLines, strBytes) else: if strLastLoggingStatus <> "off": strCurLogStatus = "Logging: Off" strLastLoggingStatus = "off" else: if strCurLogStatus <> "": crt.Session.SetStatusText("") #update the status crt.Session.SetStatusText(strCurLogStatus) crt.Sleep(nRefreshRateMs) except Exception as objInst: crt.Session.SetStatusText( "Script failure: {}".format(str(objInst))) return main()