#!/usr/bin/env python # # Prefix your (log) files with a timestamp # # $Id: tailtime 286 2011-03-10 08:44:46Z rick $ # Rick van der Zwet # license: BSD import time import sys import os # Really make it unbuffered sys.stdin = os.fdopen(sys.stdin.fileno(), 'r', 0) sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) if __name__ == "__main__": try: strftime = sys.argv[1] except IndexError,ValueError: strftime = '%H:%M:%S' try: while 1: line = sys.stdin.readline() #XXX: Not some kind of smarter way to detect EOF? if len(line) == 0: break prefix = "[%s] " % time.strftime(strftime) print prefix + line, except KeyboardInterrupt: pass