Last change
on this file since 396 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
|
---|
8 | import time
|
---|
9 | import sys
|
---|
10 | import os
|
---|
11 |
|
---|
12 | # Really make it unbuffered
|
---|
13 | sys.stdin = os.fdopen(sys.stdin.fileno(), 'r', 0)
|
---|
14 | sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
|
---|
15 |
|
---|
16 | if __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.