source: misc/tailtime@ 352

Last change on this file since 352 was 286, checked in by Rick van der Zwet, 14 years ago

Filter after tail to show me timestamps

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 682 bytes
Line 
1#!/usr/bin/env python
2#
3# Prefix your (log) files with a timestamp
4#
5# $Id: tailtime 286 2011-03-10 08:44:46Z rick $
6# Rick van der Zwet <info@rickvanderzwet.nl>
7# license: BSD
8import time
9import sys
10import os
11
12# Really make it unbuffered
13sys.stdin = os.fdopen(sys.stdin.fileno(), 'r', 0)
14sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
15
16if __name__ == "__main__":
17 try:
18 strftime = sys.argv[1]
19 except IndexError,ValueError:
20 strftime = '%H:%M:%S'
21 try:
22 while 1:
23 line = sys.stdin.readline()
24 #XXX: Not some kind of smarter way to detect EOF?
25 if len(line) == 0:
26 break
27 prefix = "[%s] " % time.strftime(strftime)
28 print prefix + line,
29 except KeyboardInterrupt:
30 pass
Note: See TracBrowser for help on using the repository browser.