source: misc/tailtime@ 356

Last change on this file since 356 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
RevLine 
[145]1#!/usr/bin/env python
[286]2#
3# Prefix your (log) files with a timestamp
4#
[145]5# $Id: tailtime 286 2011-03-10 08:44:46Z rick $
6# Rick van der Zwet <info@rickvanderzwet.nl>
7# license: BSD
8import time
[286]9import sys
[145]10import os
11
[286]12# Really make it unbuffered
13sys.stdin = os.fdopen(sys.stdin.fileno(), 'r', 0)
14sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
[147]15
[286]16if __name__ == "__main__":
17 try:
18 strftime = sys.argv[1]
19 except IndexError,ValueError:
20 strftime = '%H:%M:%S'
21 try:
[145]22 while 1:
[286]23 line = sys.stdin.readline()
24 #XXX: Not some kind of smarter way to detect EOF?
25 if len(line) == 0:
[145]26 break
[286]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.