Created
January 11, 2024 23:23
-
-
Save gkeramidas/8b048a28b97be28fa21ebbb90dea2153 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import datetime | |
import sys | |
def timestamp(): | |
now = datetime.datetime.now() | |
return (now.strftime('%Y-%m-%d %H:%M:%S.%m') + | |
".%06d" % now.microsecond) | |
if __name__ == '__main__': | |
try: | |
while True: | |
line = sys.stdin.readline() | |
if line == '': | |
break | |
line = line.rstrip('\n\r') | |
sys.stdout.write("%s -- %s\n" % (timestamp(), line)) | |
sys.stdout.flush() | |
except KeyboardInterrupt: | |
sys.stderr.write('Interrupted') | |
sys.exit(1) # interrupted | |
except IOError: | |
sys.exit(74) # EX_IOERR from sysexits.h | |
except: | |
sys.exit(70) # EX_SOFTWARE from sysexits.h | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment